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...
-
The following data refer to Flintoff Fashions for the current year: Required: 1. Required the schedule of cost of goods manufactured for Flintoff Fashions. 2. Prepare the schedule of cost goods sold...
-
The major result of a financial audit conducted by an independent accountant is the expression of an opinion by the auditor on the fairness of the financial statements. While the auditor's report...
-
Today is September 16, Year 2. You, CPA, work for Garcia & Garcia LLP, a medium-sized firm located in Montreal. Jules Garcia calls you into his office. "CPA, I have a very special engagement for you....
-
Consider the following terms: Entropy Carnot cycle Cyclical process Heat engine Internal energy Isochoric process Isothermal process Choose at least 2 terms from the list and answer the following...
-
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...
-
The controller for Crombie Inc. has established the following activity cost pools and cost drivers. Each order must be a minimum of 1,000 boxes of film chemicals. The production requirements for each...
-
Many factors affect the economics of sport. What are some not discussed in the chapter? How do they affect financial management within the industry?
-
Ethical evaluation is considered a waste of time when the project is forecast to succeed. True/False
-
Which has the greater impact on financial management: the structure of a league or the structure of a team?
-
Bowie and Velasquez discussed ethical issues, which are uncertainties and the ability to execute a project during decision making. True/False
-
Developing good character is crucial to consequentialism. True/False
-
Repeat Prob. 482 for the vertical deflection at point A. Prob. 482, The part shown is formed from a 1/8 -in diameter steel wire, with R = 5 in and l = 4 in. A force is applied with P = 1 lbf. Use...
-
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?
-
ArrayList and Classes Imagine you want to create a program to keep track of a collection you have. If you don't actually have a collection, you can have your program work as a wish list instead. You...
-
Make sure that I can be able to merge two sorted arrays into one. For some reason my Eclipse is not running my Java programs. So I need help to make sure everything runs smoothly package Test2;...
-
Consider the following implementation of a class Square: public class Square { } private int length; private int area; // create a square with given length for a side public Square (int sideLength) {...
Study smarter with the SolutionInn App