QuestionQuestion

I. The Assignment

Create an ElapsedTimeCalculator class that computes the amount of time that passes between a starting time and an ending time, in military format.

For example, suppose the two times are 1445 and 1730. Then the program output should look something like this:

Start time: 1445
End time: 1730

Exactly 2 hour(s) and 45 minute(s) have passed.

Total elapsed time in minutes: 165
Total elapsed time in hours: 2.75

II. ElapsedTimeCalculator Class Specifications

1. Your class will have two int instance variables that store the two times, and a constructor that takes two int parameters: the starting time and the ending time in military format

2. Your class will also have these methods:

• two accessor (aka: “get”) methods that return the starting and ending times
• a mutator (aka: “set”) method that resets the starting and ending times to values passed as parameters
• a method that computes and returns the hour portion of the elapsed time
• a method that computes and returns the minute portion of the elapsed time
• a method that computes and returns the total elapsed time in minutes
• a method that computes and returns the total elapsed time in hours

III. Test Class Specs

You test class will have a single method – main – that performs the following operations in the order listed:

1. Get the initial military start and end times from the user
2. Create an ElapsedTimeCalculator object
3. Call the accessor methods to get the times and print them
4. Call the methods that do the 4 computations, and print the values returned
5. Get a new start and end time from the user
6. Call the mutator method to reset the times - do not create a new ElapsedTimeCalculator object
7. Call the accessor methods to get the updated times and print them
8. Call the methods that do the computations again and print the new results

III. Additional Program Specs

1. Assume that the end time is always greater than the start time (i.e., later that same day)

2. All times must be entered by the user of the program

3. All output is to be done in main. I.e. none of the ElapsedTimeCalculator methods does any output

4. Although your program must work for any two times, have the user enter these 2 sets of times in the run you hand in:

Start time: 1445 End time: 1730

Start time: 1234 End time: 1811

5. Make sure that both your Java files and the output are neat and readable, and that all output is clearly labeled

IV. Hints!

1. Convert the starting and ending times to minutes before doing any other calculations!

The purpose of this assignment is to master the perils of integer arithmetic. Therefore you must use the int division and mod operations to extract the the hour and minute portions of each military time!

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public class ElapsedTimeCalculator {

    /**
    * Your class will have two int instance variables that store the two times,
    * and a constructor that takes two int parameters: the starting time and
    * the ending time in military format
    */
    private int starting;
    private int ending;

    /**
    * No credit will be given if any other constructor is called (e.g. a
    * 4-argument constructor that takes the hour portions and the minute
    * portions of the two times separately)
    *
    * @param starting the starting time in military format
    * @param ending the ending time in military format
    */
    public ElapsedTimeCalculator(int starting, int ending) {
       /**
         * Assume that the end time is always greater than the start time
         */
       this.starting = starting;
       this.ending = ending;
    }

    /**
    * two accessor (aka: “get”) methods that return the starting and ending
    * times
    */
    public int getEnding() {
       return ending;
    }

    public int getStarting() {
       return starting;
    }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$18.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Computer Science - Other Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats