Question: In this question we want to use java to design a class that models a 24-hour Clock class. Here is the skeleton of the class:

In this question we want to use java to design a class that models a 24-hour Clock class. Here is the skeleton of the class:

//This is a 24-hour clock so that 13:15 is 1:15 PM. The class should include integer variables hour and minute.

class Clock{

public Clock(); This is the default constructor of the class. It creates a Clock object and sets the time to

midnight, hour = 0, minute = 0.

public Clock(int h); This is a one-argument constructor with parameter for the hour. The constructor always sets

minute to 0.

public Clock(int h, int m); This is a two-argument constructor with parameters for the hour and minute.

public int getHour(); Returns the hour.

public int getMinute(); Returns the minute.

public void incrementTimer(); Basic incremented adds 1 minute to the time.

public void incrementTimer(int x); Adds x minutes to the time. (Hint: you can reuse the incrementTimer() method here.)

public void setTime(int h, int m);

Sets the time to be hour = h and minute = m. All values must all be range-checked to make sure they are valid. For example, 3:78 is invalid. If invalid data is entered it should print Invalid Input. Please note that both the hour and minute should be in the correct range for the time to be changed.

public String toString(); Returns a string in the form of xx:yy PM. eg. 02:53 PM, 11:05 AM, or 12:15 AM.

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!