Question: Please help with Java programming! This code is to implement a Clock class. Use my beginning code below to test your implementation. public class Clock

Please help with Java programming!

This code is to implement a Clock class.

Use my beginning code below to test your implementation.

public class Clock {

// Declare your fields here

/**

* The constructor builds a Clock object and sets time to 00:00

* and the alarm to 00:00, also.

*

*/

public Clock() {

setHr(0);

setMin(0);

setAlarmHr(0);

setAlarmMin(0);

}

/**

* setHr() will validate and set the value of the hr field

* for the clock.

*

* @param h the hour to attempt setting

*/

private void setHr( int h ) {

int tmp = 0; // default hour in case h is out of range

if ( h >= 0 && h

tmp = h; // h is valid, so set it to tmp

}

hr = tmp; // set the hr field to tmp's value

}

/**

* setMin() will validate and set the value of the min field

* for the clock.

*

* @param m the min to attempt setting

*/

private void setMin( int m ) {

}

/**

* setAlarmHr() will validate and set the value of the hr field

* for the alarm.

*

* @param h the hour to attempt setting

*/

/**

* setAlarmMin() will validate and set the value of the min field

* for the alarm.

*

* @param m the min to attempt setting

*/

/**

* getHr() simply returns the value of the hr field.

*

* @return The value of the hour for the clock

*/

private int getHr() {

return hr;

}

/**

* getMin() simply returns the value of the min field.

*

* @return The value of the min for the clock

*/

/**

* getAlarmHr() simply returns the value of the alarmHr field.

*

* @return The value of the hour for the alarm

*/

/**

* getAlarmMin() simply returns the value of the alarmMin field.

*

* @return The value of the min for the alarm

*/

/**

* setAlarm() allows the user of a Clock object to set the alarm

* time.

*

* It should call setAlarmHr() and setAlarmMin() to set the alarm.

*

* @param h an int value for the hour

* @param m an int value for the minute

*/

public void setAlarm( int h, int m ) {

}

/**

* setTime() allows the user of a Clock object to set the current

* time.

*

* It should call setHr() and setMin() to set the time.

*

* @param h an int value for the hour

* @param m an int value for the minute

*/

/**

* alarmSound() will return true if the alarm time has been reached,

* false otherwise.

*

* @return true if the alarm and clock times are equal, false

* otherwise

*/

public boolean alarmSound() {

}

/**

* tick() will increment the current time of the clock, adding

* one minute to the clock's current time, correctly handling if the

* clock advances to the next hour or the next day.

*

* You should use getHr() and getMin() as well as setHr() and

setMin()

* to implement this method.

*/

public void tick() {

}

/**

* toString() will return a String that is the current time

* formatted as HH:MM.

*

* @return A formatted String in HH:MM format.

*/

public String toString() {

return String.format( "%02d:%02d", getHr(), getMin());

}

}

Please help with Java programming! This code is to implement a Clock

class. Use my beginning code below to test your implementation. public class

Clock { // Declare your fields here /** * The constructor builds

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!