Question: Write a program that prompts the user to enter the time in 12 hours notation. The program then outputs the time in 24 hours

Write a program that prompts the user to enter the time in 

InvalidHrExcep InvalidMinExcep InvalidSecExcep - String message - String message - String message + Invalid HrExcepo +InvalidLet us look at the run time analysis: Case 1: Correct input Enter hours: 8 Enter minutes: 28 Enter seconds: 38 Enter AM or PM  
 

Write a program that prompts the user to enter the time in 12 hours notation. The program then outputs the time in 24 hours notation. Your program must contain three exception classes: InvalidHrException InvalidMinException InvalidSecException. If the user enters an invalid value for hours, then the program should throw and catch an InvalidHrException, and prompt user to re-enter the value. Similar conventions will be for the values of minutes and seconds. The following shows the UML diagrams of all the classes and their relationship that you have to implement them: O InvalidHrExcep O InvalidMinExcep O InvalidSecExcep - String message O- String message - String message O +InvalidHrExcep0 O+ InvalidMinExcep0 O + InvalidSecExcep0 O + InvalidSecExcep(String str) O+ String getmessage0 O+ String toString0 O+ InvalidHrExcep(String str) O+ InvalidMinExcep(String str) O+ String getmessage0 O+ String getmessage() O+ String toString0 O+ String toString) O Lab_4 9 - static Scanner console O + static void main(Stringl args) O + static int getHours0 O + static int getMinutes) O + static int getSeconds) O +static void print24HourTime(int hr, int min, int sec, String str) Convenient to your design, feel free to change some of the methods used in the main file. Let us look at the run time analysis: Case 1: Correct input Enter hours: 8 Enter minutes: 28 Enter seconds: 38 Enter AM or PM: Am 24 hour clock time: 08:28:38 Case 2: Wrong hours / minutes / seconds Enter hours: -3 The value of hours must be between e and 12. Enter hours: 23 The value of hours must be between e and 12. Enter hours: 9 Enter minutes: -8 The value of minutes must be between e and 60. Enter minutes: 45 Enter seconds: -9 The value of seconds must be between 0 and 60. Enter seconds: 98 The value of seconds must be between e and 60. Enter seconds: 48 Enter AM or PM: pm 24 hour clock time: 21:45:48

Step by Step Solution

3.33 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Note You have not mentioned any particular programming language So I have written it in Java Code to ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!