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:30
What is the digital revolution and how did it change society? what are the benefits of digital media?
Answers: 1
question
Computers and Technology, 23.06.2019 14:30
Open this link after reading about ana's situation. complete each sentence using the drop-downs. ana would need a minimum of ato work as a translator. according to job outlook information, the number of jobs for translators willin the future.
Answers: 3
question
Computers and Technology, 23.06.2019 15:00
Jake really works well with numbers and is skilled with computers but doesn't work well with others. which of the jobs discussed in this unit might be best for jake? why?
Answers: 3
question
Computers and Technology, 23.06.2019 18:30
Write a program that prints the day number of the year, given the date in the form month-day-year. for example, if the input is 1-1-2006, the day number is 1; if the input is 12-25-2006, the day number is 359. the program should check for a leap year. a year is a leap year if it is divisible by 4, but not divisible by 100. for example, 1992 and 2008 are divisible by 4, but not by 100. a year that is divisible by 100 is a leap year if it is also divisible by 400. for example, 1600 and 2000 are divisible by 400. however, 1800 is not a leap year because 1800 is not divisible by 400.
Answers: 3
You know the right answer?
This lab has two parts:

Create a TimeException class.
Create a program that contin...
Questions
question
English, 16.11.2020 22:50
question
Mathematics, 16.11.2020 22:50
question
History, 16.11.2020 22:50
question
Social Studies, 16.11.2020 22:50
question
Mathematics, 16.11.2020 22:50
question
Mathematics, 16.11.2020 22:50
Questions on the website: 13722362