Question: In this question, you are asked to design a class that models a 24-hour Clock class. Here is the skeleton of the class: //This is

In this question, you are asked 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.

} 

Sample Input 1:

0 print q

Sample Output 1:

Creating clock with hour = 0 and minute = 0 Printing the time 12:00 AM

Sample Input 2:

1 13 print q

Sample Output 2:

Please enter 1 integer to create a Clock object Creating clock with hour = 13 Printing the time 01:00 PM

Sample Input 3:

2 14 6 print q

Sample Output 3:

Please enter 2 integers to create a Clock object Creating clock with hour = 14 and minute = 6 Printing the time 02:06 PM

Sample Input 4:

2 14 58 incrementOne getHour getMinute q

Sample Output 4:

Please enter 2 integers to create a Clock object Creating clock with hour = 14 and minute = 58 Incrementing timer with 1 minute New Time: 14 59 hour: 14 minute: 59

Sample Input 5:

2 14 58 incrementMult 3 getHour getMinute q

Sample Output 5:

Please enter 2 integers to create a Clock object Creating clock with hour = 14 and minute = 58 Please enter how many minutes you want to increment the timer New Time: 15 1 hour: 15 minute: 1

---------

Please help me!

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!