Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions