Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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());

}

}

image text in transcribed

image text in transcribed

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions

Question

How many multiples of 4 are there between 10 and 250?

Answered: 1 week ago

Question

How many three-digit numbers are divisible by 7?

Answered: 1 week ago