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?
-
Differentiate between each of the following pairs of terms: a.Money market and capital market b.Primary market and secondary market c.Broker market and dealer market
-
Perform the planning tasks (only for the knowledge areas covered in this chapter) for one of the case studies provided in Appendix C. Remember to be thorough in your planning so that your execution...
-
Identify the five planning tools provided in Integrated Accounting 6e.
-
Marshall Inc. experiences a fire in its warehouse at the end of the year, which destroys its entire inventory. Marshall's records show that it started the year with $35,000 of inventory and purchased...
-
Gift giving can cause ethical dilemmas for professional accountants working in a global environment. Discuss this issue in relation to cross-national business transactions and outline how cultural...
-
Larry has severe vision problems and, in the past, he has claimed the additional standard deduction available to blind taxpayers. This year Larrys doctor prescribed a new type of contact lens that...
-
Rubick is an employee of Radiant Financial Corporation Ltd.He has been assigned the task of preparing budget for the company. He observed that in previous year budget was prepared on the basis of...
-
Assume that a company is choosing between two alternatives-keep an existing machine or replace it with a new machine. The costs associated with the two alternatives are summarized as follows:...
-
than a full box. When he is done, there are 67 bottles in the refrigerator. Write and solve an equation to find the number of bottles in a full box.
-
A stock is expected to pay a dividend of 1.5 per share in 2 and 5 months. The stock price currently stands at 100. The continuously compounded risk-free rate is 4% per annum. 1) What should be the...
-
A manufacturing company that produces a single product has provided the follow data concerning its most recent month of operations: Selling price $166 Units in beginning inventory 100 Units produced...
-
4. Given the financial ratio and operating benchmarks below, assess the hospital's performance and provide recommendations to improve financial performance. Profitability Hospital Median 25th 75th %...
-
Labels June 30 Cost of goods sold Fixed costs For the Month Ended June 30 For the Month Ended May 3.1 May 31 Variable cost of goods sold Amount Descriptions Contribution margin Contribution margin...
-
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...
-
A retailer purchases a can of soup for 24 cents and sells it for 36 cents. Calculate the markup as a percentage of cost and as a percentage of selling price.
-
The characteristics of services affect the development of marketing mixes for services. Choose a specific service and explain how each marketing mix element could be affected by these service...
-
Identify a familiar product that recently was modified, categorize the modification (quality, functional, or aesthetic), and describe how you would have modified it differently.
Study smarter with the SolutionInn App