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% (2 reviews)
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...
-
For the past 10 years, Prince Company (Prince) has owned 75,000 or 75% of the common shares of Stiff Inc. (Stiff). Elizabeth Winer owns another 20% and the other 5% are widely held. Although Prince...
-
What is catering theory, and how does it impact a firms dividend policy? AppendixLO1
-
Robert Campbell and Carol Morris are senior vice presidents of the Mutual of Chicago Insurance Company. They are codirectors of the companys pension fund management division, with Campbell having...
-
Mr. Kamal is planning to set up a mini Zoo in Amwaj Islands. $25 per person will be the price for visiting the zoo. In addition, the variable costs per visitor will be $9 and total fixed costs are...
-
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...
-
Cosmos and Wanda will not grant Timmy's wishes if and only if Timmy Turner is 10 years old or he does not have fairly odd parents. Assume the following statements are true. \(p\) : "Poof is a baby...
-
Dr. Kovaleski is interested in examining whether quantity of sleep impacts problem solving ability. To test problem solving ability, the research team gave participants a puzzle and measured how long...
-
Can you please help me fill out the spreadsheet? Idexo Corporation is a privately held designer and manufacturer of licensed college apparel in Cincinnati, Ohio. In late 2020, after several years of...
-
CHECK FIGURE: Adjusted book balance = $2,837.06 Mae Telford, the controller of the Baylor Company, provided the following information: Bank statement balance Add: Baylor Company Bank Reconciliation...
-
Read the Scenario Congratulations, you are now the Police Chief in Anytown, USA. A city with 30,000 residents and you are responsible to provide 24 hour a day police coverage. You have a total of 45...
-
Here are summary statistics for randomly selected weights of newborn girls: n = 36, x = 3180.6 g, s = 700.5 g. Use a confidence level of 99% to complete parts (a) through (d) below. a. Identify the...
-
Draw a graph of a function for which the domain is [-4, 4] and the range is U [3, 5].
-
Using the parallel-axis theorem, determine the product of inertia of the area shown with respect to the centroidal x and y axes. 6 in. 9 in. 9 in- 4.5 in. in. 4.5 in.
-
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?
-
Aecerty 1067687 was completed with the folowing charaderistick Murulectere sec00 5xs:99 s35ida sputed
-
Assume todays settlement price on a CME EUR futures contract is $1.3180 per euro. You have a long position in one contract. EUR125,000 is the contract size of one EUR contract. Your performance bond...
-
Q2. Company ABC bought an equipment for $20,000 in 2015, with useful life of 5 years $5,000 residual value amortized using straight-line method. Prepare a table to illustrate the differences...
Study smarter with the SolutionInn App