Write a program that prompts the user to enter the time in 12 hours notation. The...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 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
Expert Answer:
Answer rating: 100% (QA)
Note You have not mentioned any particular programming language So I have written it in Java Code to ... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
Write a program that prompts the user to enter three strings. Compare the String objects lexicographically and print the middle-valued string. For example, if the three strings were "abcd", "wxyz",...
-
Write a program that prompts the user to enter the length from the center of a pentagon to a vertex and computes the area of the pentagon, as shown in the following figure. The formula for computing...
-
Write a program that prompts the user to enter three cities and displays them in ascending order. Here is a sample run: Enter the first city: Chicago JEnter Enter the second city: Los Angeles JEnter...
-
What are the four different elements of advertising? Are all of them appropriate to an average retailer in most markets?
-
Explain the following statement: Horizontal consistency of goals is as important as vertical consistency.
-
The density function of the random vector \((\xi, \eta, \zeta)\) is \[ ho(x, y, z)=\left\{\begin{array}{cc} \frac{6}{(1+x+y+z)^{4}} & \text { for } x>0, y>0, z>0 \\ 0 & \text { otherwise }...
-
Suppose Sports-R-Us purchases $40,000 of sportswear on account from Pacific Trail on March 1,2010. Credit terms are 2/10, net 30. Sports-R-Us pays Pacific Trail on March 8, 2010. 1. Journalize the...
-
Giant Jets is a French company that produces jet airplanes for commercial cargo companies. The selling price (in euros) per jet is 1,000,000. Currently the company uses actual volumes to allocate...
-
You work for Frederick and Sons Company (FSC) as the VP Finance. FSC's CEO (your boss), I.M. Confewzed, is currently sitting in your office with the financial statements that you prepared for 2017...
-
The country of Emmental has three firms, whose information is displayed below (in thousands). Fill in the missing information (also in thousands). Assume that no international trade exists and that...
-
Which of the followings is considered as a prototype of dopaminergic agents: O a. Levodopa b. Pramipexole c. Rasagiline d. Ropinirole
-
A secondary clarifier is 75 ft in diameter and receives a primary effluent flow 3.1 MGD and a return sludge 0.9 MGD. If the MLSS concentration is 3140 mg/L, what is the solids loading rate on the...
-
An analytical chemist is titrating a 50.0 mL solution with an unknown concentration of bromide (Br-) using 0.0500 M AgNO3.Silver and bromide precipitate with a Kspof 1.50 x 10-13. a) Addition of 10.0...
-
D . Reichenbach Co . , organized in 2 0 1 9 , has set up a single account for all intangible assets. The following summary discloses the debit entries that have been recorded during 2 0 2 0 and 2 0 2...
-
A CAT scan of a human pancreas shows cross-sections spaced 1 cm apart. The pancreas is 12 cm long and the cross-sectional areas, in square centimeters, are 7.5, 15.0, 18.0, 10.3, 11.0, 9.7, 8.9, 7.7,...
-
What is wrong with the following program? (10) #include namespace std; int main() { } cout
-
35c) Using set notation of the form {...., #,#,#, ...}, write the residue classes modulo 5 in Z. Also, list The elements of 21/521. 0 = {... I= {... - 2 {... = -- - - 15, 10, -5, 0, 5, 10, 15, ...} =...
-
The pendulum consists of two rods: AB is pin supported at A and swings only in the y-z plane, whereas a bearing at B allows the attached rod BD to spin about rod AB. At a given instant, the rods have...
-
Write a program that prompts the user to enter three integers and display the integers in non-decreasing order.
-
Write a program to create a file named Exercise12_15.txt if it does not exist. Write 100 integers created randomly into the file using text I/O. Integers are separated by spaces in the file. Read the...
-
Write a program that enables the user to drag the vertices of a triangle and displays the angles dynamically as the triangle shape changes, as shown in Figure 15.30a. The formula to compute angles is...
-
What is a bivariate distribution function?
-
True or False. The expected value of \(x\), in terms of its probability density function, \(p(x)\), is given by \(\int_{-\infty}^{\infty} x p(x) d x\).
-
Find the temporal mean value and the mean square value of the function \(x(t)=x_{0} \sin (\pi t / 2)\).
Study smarter with the SolutionInn App