Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Clock class to represent the time of day in a program. This class should be defined as a separate file within your Java

Write a Clock class to represent the time of day in a program. This class should be defined as a separate file within your Java Project. Points will be deducted if the class is embedded as an inner class. This does not affect the name of your Java Project above.

Suppose that the time is represented as a set of three integers: one to represent the hours, one to represent the minutes, and another to represent the seconds.

hr: an integer to store the hours

min: an integer to store the minutes

sec: an integer to store the seconds

The class should have the following methods:

Constructor: default constructor (i.e. no-arg constructor) that initializes all fields to 0.

Consructor: accepts values specified by the user for each field as an argument.

setTime: sets the time to the time specified by the user. The method header is: public void setTime(int hours, int minutes, int seconds)

getHours: returns the hours.

getMinutes: returns the minutes.

getSeconds: returns the seconds.

printTime: prints the time in the form hh:mm:ss. The method header is: public void printTime()

incrementHours: increments the time by one hour.

incrementMinutes: increments the time by one minute.

incrementSeconds: increments the time by one second.

equals: compares two times to determine whether they are equal. The method header is: public boolean equals(Clock otherClock)

makeCopy: copies the time of one Clock object into another Clock object. See Chapter 8 content on deepcopy to assist with developing this method. The method header is: public void makeCopy(Clock otherClock)

getCopy: returns a copy of the time. A copy of the object's time is created and a reference to the copy is returned. The method header is: public Clock getCopy()

digitalClockGame: plays the Amazing Digital Clock Game. There is a belief that if at any time a person takes a look at a digital clock, with standard time, and if the digits of the hours, minutes, and seconds add up equally for the three parts, it is a good time, or actually a lucky time that will predict or is a forecast that whatever you were thinking/wishing at that instant, might come true. For example, 11:02:20, 5:14:23, or 12:03:30 are considered as lucky times. Besides that, there are three other special times that also carry specific meanings. If all digits are the same, like 4:44:44 or 5:55:55, it predicts you might win a lottery. If all digits are in ascending order, like 2:34:56 or 1:23:45, it predicts all dreams will come true. If all digits are in descending order, like 6:54:32 or 5:43:21, it predicts a challenging road is ahead. When this method is executed, it should prompt the user to enter a time in the format hh:mm:ss. Then the method will tell if the time is a lucky time or just a normal time. And then, if the time carries a specific meaning, as described above, the corresponding meaning should be displayed also.

-------

Write a menu-driven program that demonstrates the Clock class. Use the menu below.

Welcome to the Digital Clock Program! Please choose an option below.

1. Set the time. 2. Return the hours. 3. Return the minutes. 4. Return the seconds. 5. Print the time. 6. Increment the time by one hour. 7. Increment the time by one minute. 8. Increment the time by one second. 9. Compare two times for equality. 10. Play Amazing Digital Clock. 11. Quit.

Your program should prompt continuously after a selection is made. Do not end the program until Quit is selected.

Input Validation: Do not accept unreasonable time, negative values, or junk values, which must be rejected and asked for another one.

Be sure that clear instructions are given to the user.

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

Step: 3

blur-text-image

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

International Baccalaureate Computer Science HL And SL Option A Databases Part I Basic Concepts

Authors: H Sarah Shakibi PhD

1st Edition

1542457084, 978-1542457088

More Books

Students also viewed these Databases questions

Question

Challenges Facing Todays Organizations?

Answered: 1 week ago