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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 14:20, ashl3yisbored
The concept of comes from the acknowledgment that data changes form and often gets copied, moved, and stored in many places. sensitive data often leaves the protection of application databases and ends up in e-mails, spreadsheets, and personal workstation files.
Answers: 3
image
Computers and Technology, 22.06.2019 19:20, ChaosMind
Write a program that reads a file consisting of students’ test scores in the range 0–200. it should then determine the number of students having scores in each of the following ranges: 0–24, 25–49, 50–74, 75–99, 100–124, 125–149, 150–174, and 175–200. output the score ranges and the number of students. (run your program with the following input data: 76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189.)
Answers: 3
image
Computers and Technology, 24.06.2019 07:40, daebreonnakelly
What type of multimedia are live news feeds? live news feeds are examples of multimedia.
Answers: 2
image
Computers and Technology, 24.06.2019 08:50, bo4isbad
Write a program that will compute the volume of ice cream served in a cone. as you can see in the diagram below, the ice cream is served as a hemisphere of frozen deliciousness on top of a cone, which is also packed with frozen deliciousness. thus, the total volume of ice cream sold is the volume of the hemisphere plus the volume of the cone. the example shows an ice cream cone in which the hemisphere and cone have a radius of 10 inches and the cone has a height of 15 inches. your program must instead prompt for these two values, which are taken from the keyboard as integers: • the hemisphere/cone radius in inches, and
Answers: 3
You know the right answer?
This lab has two parts:

Create a TimeException class.
Create a program that contin...

Questions in other subjects:

Konu
Mathematics, 01.10.2021 04:00
Konu
Mathematics, 01.10.2021 04:10