subject

This lab has two parts:

Create a TimeException class.
Create a program that continually asks the user for a 24-hour time and uses the TimeException if the time is too large or small.
Task 1 – TimeException Class

Create a TimeException class by creating a new class that extends from the built-in exception class. The only additional step is to create a parameterized constructor that takes in a string which will be the error message given back to the user.

Task 2 – Main Program

Create a Tester Class, with a Main method. In the Main method, create a loop that will continue to execute until the user enters "n", otherwise the loop should continue. Each iteration of the loop will begin by asking the user to enter a time in the 24-hour format, including the colon ":". That means that numbers given from zero (0) to twenty-three (23) will be appropriate for the hours' place. The minutes will still be in the same range, going from zero (0) to fifty-nine (59).

The next step in this loop will be to convert the given time from a string (which includes ":") to a number format (which does not include ":"). At this point, please use the already created NumberFormatException (in Java) or FormatException (in C#) to handle cases where the user did not enter a number. If an exception does occur, please print the relevant error message using the Exception class’s printStackTrace (in Java) or StackTrace (in C#), as well continuing the loop to the next iteration and starting the process over again by asking the user for another 24-hour time.

After that the following step is reduce the number of hours if they are over twelve (12) so that we can see the equivalent 12-hour time. There is also a special case for the hour zero (0), which is our twelve (12) or midnight hour. Here is where we should throw and catch our TimeException if the number of hours is twenty-four (24) or over, or if it is under zero (0). We should also use this TimeException if the number of minutes is over fifty-nine (59) or under zero (0). If an exception does occur, print the relevant error message using the same method above, after which please continue the loop to the next iteration and start the process over again as well.

Finally, we print out the converted hours along with "AM" or "PM", and then ask the user if they wish to continue and start the loop over again.

∃ Some Sample Output:

Enter a time in 24-hour format: 14:15
Same time in 12-hour format: 2:15 PM
Continue? y

Enter a time in 24-hour format: 20:50
Same time in 12-hour format: 8:50 PM
Continue? y

Enter a time in 24-hour format: 25:50

The number of hours was not valid, try again.
Enter a time in 24-hour format: 2:80
The number of minutes was not valid, try again.

Enter a time in 24-hour format: 2:30
Same time in 12-hour format: 2:30 AM
Continue? Y

Enter a time in 24-hour format: 0:05
Same time in 12-hour format: 12:05 AM
Continue? N

Program has finished!

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 23:20
How can you tell if someone sent you a text message to your email instead of a email
Answers: 1
question
Computers and Technology, 23.06.2019 22:00
Take a critical look at three gui applications you have used—for example, a spreadsheet, a word-processing program, and a game. describe how well each conforms to the gui design guidelines listed in this chapter.
Answers: 3
question
Computers and Technology, 24.06.2019 00:20
Describe a data structures that supports the stack push and pop operations and a third operation findmin, which returns the smallest element in the data structure, all in o(1) worst-case time.
Answers: 2
question
Computers and Technology, 24.06.2019 10:50
In 2009 to 2010, how many social network users were reported as being victims of online abuse? a. 1 in 10 b. 100% c.1 in 100 d. 50%
Answers: 2
You know the right answer?
This lab has two parts:

Create a TimeException class.
Create a program that contin...
Questions
question
Biology, 05.10.2020 14:01
question
Spanish, 05.10.2020 14:01
question
Mathematics, 05.10.2020 14:01
question
Mathematics, 05.10.2020 14:01
Questions on the website: 13722362