Modify class Time2 of Fig. 8.5 to include a tick method that increments the time stored in
Question:
Modify class Time2 of Fig. 8.5 to include a tick method that increments the time stored in a Time2 object by one second. Provide method incrementMinute to increment the minute by one and method incrementHour to increment the hour by one. Write a program that tests the tick method, the incrementMinute method and the incrementHour method to ensure that they work correctly. Be sure to test the following cases:
a) Incrementing into the next minute,
b) Incrementing into the next hour and
c) Incrementing into the next day (i.e., 11:59:59 PM to 12:00:00 AM).
Fig. 8.5
Transcribed Image Text:
I 2 3 5 6 7 8 9 10 II 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 // Fig. 8.5: Time2.java // Time2 class declaration with overloaded constructors. public class Time2 { private int hour; // 0 - 23 private int minute; // 0 - 59 private int second; // 0 - 59 // Time2 no-argument constructor: // initializes each instance variable to zero public Time2() { this (0, 0, 0); // invoke constructor with three arguments } // Time2 constructor: hour supplied, minute and second defaulted to 0. public Time2(int hour) { this (hour, 0, 0); // invoke constructor with three arguments } // Time2 constructor: hour and minute supplied, second defaulted to 0 public Time2 (int hour, int minute) { this (hour, minute, 0); // invoke constructor with three arguments } // Time2 constructor: hour, minute and second supplied public Time2(int hour, int minute, int second) { if (hour < 0 11 hour >= 24) { throw new } IllegalArgumentException("hour must be 0-23"); if (minute < 0 || minute >=60) { throw new Illegal ArgumentException ("minute must be 0-59"); } if (second0 | second >=60) { throw new Illegal ArgumentException ("second must be 0-59"); } this.hour hour; this.minute = minute; this.second = second; } // Time2 constructor: another Time2 object supplied public Time2 (Time2 time) { // invoke constructor with three arguments this (time.hour, time.minute, time.second); } // Set Methods // set a new time value using universal time; // validate the data public void setTime(int hour, int minute, int second) { if (hour < 0 11 hour >= 24) { throw new IllegalArgumentException ("hour must be 0-23"); } if (minute < 0 || minute >=60) { throw new IllegalArgumentException ("minute must be 0-59"); } if (second < 0 || second >= 60) throw new IllegalArgumentException ("second must be 0-59"); } this.hour hour; this.minute = minute; this.second = second; } // validate and set hour public void setHour(int hour) { if (hour 0 11 hour >= 24) { throw new Illegal ArgumentException ("hour must be 0-23"); } 112 113 114 115 116 117 118 119 } 120 } this.hour hour; } // validate and set minute public void setMinute(int minute) { if (minute <0 || minute >=60) { throw new Illegal ArgumentException ("minute must be 0-59"); } this.minute = minute; } // validate and set second public void set Second(int second) { if (second < 0 || second >=60) { throw new Illegal ArgumentException ("second must be 0-59"); } this.second second; } // Get Methods // get hour value public int getHour() {return hour;} // get minute value public int getMinute() {return minute;} //get second value: public int getSecond() {return second;} // convert to String in universal-time format (HH:MM:SS) public String toUniversal String() { return String.format( "%02d:%02d:%02d", getHour(), getMinute(), getSecond()); } // convert to String in standard-time format (H:MM:SS AM or PM) public String toString () { return String.format("%d:%02d:%02d %s", ((getHour() == 0 11 getHour() == 12) ? 12: getHour () % 12), getMinute(), getSecond(), (getHour() < 12 ? "AM" : "PM"));
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 100% (1 review)
Based on the provided image of Time2java we will enhance the Time2 class by adding the tick incremen...View the full answer
Answered By
Utsab mitra
I have the expertise to deliver these subjects to college and higher-level students. The services would involve only solving assignments, homework help, and others.
I have experience in delivering these subjects for the last 6 years on a freelancing basis in different companies around the globe. I am CMA certified and CGMA UK. I have professional experience of 18 years in the industry involved in the manufacturing company and IT implementation experience of over 12 years.
I have delivered this help to students effortlessly, which is essential to give the students a good grade in their studies.
3.50+
2+ Reviews
10+ Question Solved
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Question Posted:
Students also viewed these Computer science questions
-
Case Study: Quick Fix Dental Practice Technology requirements Application must be built using Visual Studio 2019 or Visual Studio 2017, professional or enterprise. The community edition is not...
-
Managing Scope Changes Case Study Scope changes on a project can occur regardless of how well the project is planned or executed. Scope changes can be the result of something that was omitted during...
-
The Crazy Eddie fraud may appear smaller and gentler than the massive billion-dollar frauds exposed in recent times, such as Bernie Madoffs Ponzi scheme, frauds in the subprime mortgage market, the...
-
For this final discussion board, please reflect back on your accounting courses and answer the following questions: 1. Which course in the accounting program did you find to be the most difficult? 2....
-
Consider the flow over a circular cylinder; the incompressible flow over such a cylinder is discussed in Sec. 3.13. Consider also the flow over a sphere; the incompressible flow over a sphere is...
-
Write a short description of the motion of a real object for which FIGURE EX1.20 would be a realistic position-versus-time graph. Figure EX 1.20 x (mi) 120- 80- 40- (h) 3 4 5 2
-
Consider the following cash flow profile, and assume MARR is 10 percent/year and the finance rate is 4 percent/year. a. Determine the MIRR for this project. b. Is this project economically...
-
Palmer Co. is evaluating the appropriate accounting for the following items. 1. Management has decided to switch from the FIFO inventory valuation method to the LIFO inventory valuation method for...
-
Ricardo works for Bank B and is talking about loans with a consumer. He provides the consumer with a general explanation regarding the basic qualifications of a loan. Although the consumer plans to...
-
Modify class Date of Fig. 8.7 to perform error checking on the initializer values for variables month, day and year (currently it validates only the month and day). Provide a method nextDay to...
-
Create class SavingsAccount. Use a static variable annualInterestRateto store the annual interest rate for all account holders. Each object of the class contains a private instance variable...
-
Explain why the acid-catalyzed dehydration of an alcohol is a reversible reaction, whereas the base-promoted dehydrohalogenation of an alkyl halide is an irreversible reaction
-
1. Differentiate between a Zener diode and a regular diode in terms of their applications and characteristics. 2. Distinguish between Zener voltage and breakdown voltage in semiconductor devices. 3....
-
1. Two children are pushing a door with forces F= 75N and F= 60N, as shown in the figure. Their pushes are balanced, and the door does not move. What is the angle of F with the door? The length of...
-
13) The radiated emissions of a cable are being measured as shown in figure below at 100 MHz. Calculate the magnitude of the radiated electric field (in dBV/m) due to common-mode components of the...
-
(c) A space ship, Galactica is moving at a speed of 0.5c with a clock on board. By using the Lorentz time dilation equation, find the time elapsed for the clock on Earth if the moving clock in...
-
Consider 3 point charges q = 10 C, q= -11 C, q,- 10 C arranged in a horizontal line, as shown. 512 q 92 93 Determine the net electrostatic force acting on q, due to the other two charges, if the...
-
How do stock prices react to dividend announcements?
-
Evaluate how many lines there are in a true rotational spectrum of CO molecules whose natural vibration frequency is w = 4.09 1014 s1 and moment of inertia I = 1.44 1039 g cm2.
-
Compare and contrast the properties of a centralized and a distributed routing algorithm. Give an example of a routing protocol that takes a centralized and a decentralized approach.
-
What is meant by a control plane that is based on logically centralized control? In such cases, are the data plane and the control plane implemented within the same device or in separate devices?...
-
What is ment by a control plane that is based on per-router control? In such cases, when we say the network control and data planes are implemented monolithically, what do we mean?
-
1. Determine the centroid and the moment of inertia of the following section for the x and y centroidal axes. 1010101010 10 160 10
-
A tubular MF system treating an industrial wastewater is operated with an influent flow rate of 120 L/min, a flux of 45L/m2 h, and a recovery of 95%. Each membrane module contains 3.0m2 of membrane....
-
Write the name and formula for the conjugate bases of the following: Remember acids donate so they will lose a H+, resulting in 1 less H and 1 less + Ex. Acid (A) Conjugate Base (CB) HPO4 2- ...
Study smarter with the SolutionInn App