Question: Java Code: Suppose that you are provided with a pre - written class Clock as described below. ( The headings are shown, but not the
Java Code: Suppose that you are provided with a prewritten class Clock as described below. The headings are shown, but not the method bodies, to save space. Assume that the fields, constructor, and methods shown are already implemented. You may refer to them or use them in solving this problem if necessary.
A Clock object represents an hour:minute time during
the day or night, such as : AM or : PM
public class Clock
private int hour;
private int minute;
private String amPm;
Constructs a new time for the given hourminute
public Clockint hour, int minute, String amPm
returns the field values
public int getHour
public int getMinute
public String getAmPm
returns String for time; for example, : PM
public String toString
your method would go here
Write an instance method named advance that will be placed inside the Clock class to become a part of each Clock object's behavior. The advance method accepts a number of minutes as its parameter and moves your object forward in time by that amount of minutes. The minutes passed could be any nonnegative number, even a large number such as or If necessary, your object might wrap into the next hour or day, or it might wrap from the morning AM to the evening PM or vice versa. A Clock object doesn't care about what day it is; if you advance by minute from : PM it becomes : AM
For example, if the following object is declared in client code:
Clock time new ClockPM;
The following calls to your method would modify the object's state as indicated in the comments:
time.advance; : PM
time.advance; : PM
time.advance; : PM
time.advance; : PM
time.advance; : PM
time.advance; : AM
time.advance; : AM day later
time.advance; : PM weeks later
Assume that the state of the object is valid at the start of the call and that the amPm field stores either AM or PM
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
