Question: Exercise 1-Adding a tester and a method (3 points) The exercise must be completed during the lab period. Write a program that reads in two

 Exercise 1-Adding a tester and a method (3 points) The exercise

Exercise 1-Adding a tester and a method (3 points) The exercise must be completed during the lab period. Write a program that reads in two times in military format; e.g. 0900 representing 9:00 am or 1730 representing 5:30 pm and prints the amount of time between the two times as number of hours and minutes. The times can be entered in either order and get the same result. Use the Scanner class for input. Assume both times are the same day of the week. Implement the class TimeInterval whose constructor takes in the two times as ints. The class should have three methods: getHours, getMinutes and getDecimalTime. The constructor must test for illegal times (e.g., 2730 or -730) and print an error message. In the event of an error, terminate the program (System.exit(0)) Create a class Testrimeinterval that uses the Scanner class to get the input (that is,the two times) and produces the following results: Please enter the first time: 0400 Please enter the second time: 1530 Elapsed time in hrs/min: 11 hours 30 minutes 11.5 hours Elapsed Time in decimal: The reverse entry gives the same result: Please enter the first time: 1530 Please enter the second time: 0400 Elapsed time in hrs/min: 11 hours 30 minutes 11.5 hours Elapsed Time in decimal: HINT: Use integer division to divide the entered time into hours and minutes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!