Computers and Technology
Computers and Technology, 06.04.2020 18:09, bran1974

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!

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 17:30, Samsonb
Working on this program in python 3.7: a year in the modern gregorian calendar consists of 365 days. in reality, the earth takes longer to rotate around the sun. to account for the difference in time, every 4 years, a leap year takes place. a leap year is when a year has 366 days: an extra day, february 29th. the requirements for a given year to be a leap year are: 1) the year must be divisible by 42) if the year is a century year (1700, 1800, the year must be evenly divisible by 400some example leap years are 1600, 1712, and 2016.write a program that takes in a year and determines whether that year is a leap year. ex: if the input is 1712, the output is: 1712 is a leap year. ex: if the input is 1913, the output is: 1913 is not a leap year. your program must define and call the function isleapyear(useryear). the function should return true if the input year is a leap year and false otherwise.
Answers: 1
image
Computers and Technology, 22.06.2019 21:00, daniella0123
Simon says is a memory game where "simon" outputs a sequence of 10 characters (r, g, b, y) and the user must repeat the sequence. create a for loop that compares the two strings starting from index 0. for each match, add one point to userscore. upon a mismatch, exit the loop using a break statement. assume simonpattern and userpattern are always the same length. ex: the following patterns yield a userscore of 4: simonpattern: rrgbryybgy userpattern: rrgbbrybgy
Answers: 2
image
Computers and Technology, 24.06.2019 02:30, journeyhile5
How to apply the fly in effect to objects on a slide
Answers: 1
image
Computers and Technology, 24.06.2019 11:30, smann211
Convert 11001110(acdd notation) into decimal
Answers: 2
Do you know the correct answer?
This lab has two parts:

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

Questions in other subjects: