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!