Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class that represents the hour minute and seconds of a Clock, with a constructor for military time (hour, minute and second) and default

Create a class that represents the hour minute and seconds of a Clock, with a constructor for military time (hour, minute and second) and default time that sets the value to midnight. A getTime() method will return the time as a String.

To protect the hour, minute and seconds value, the setters will not allow setting an invalid minute. All values greater than the valid range will set the value using the modulus value and all values less than the valid range will set the value to zero. There will be no "carrying over" values. For example 72 minutes will be set to 12 minutes, no additional hours (72 % 60) and -5 minutes will be set to 5. See the examples for details.

Create a new project for the assignment.

Create a new class called Clock

Create three integer attributes for hour, minute and second.

Always store the hour in military time.

Create setters for the hour, minute and second values. To demonstrate encapsulation and protect the values stored in these variables, make sure that any value sent to the setters is reduced to a valid range for the value. Use the modulus operator to reduce the value to a valid range. For example: minute % 60. Use the Math.abs(int) method to make sure the values are all positive.

setMinute(): use the range 0-59

setSecond(): use the range 0-59

setMilitaryHour(): use the range 0-23. Notice that the military time is all that is stored in the Clock class.

Create Constructors using the setters created in the previous steps. The constructors should accept military time as parameters (hour, minute, second)

Create getters for the hour minute and second value.

getMilitaryHour() must return the stored military time

getMinute() must return the stored minutes

getSecond() must return the stored second

Create a toString() method that returns the value as a formatted time String. Remember that values less than 10 must be padded with zeroes. For example, midnight will look like this returned from getMilitaryTime(): 00:00:00. Use the StringzeroPad(int) method to pad the numbers - see the code below. Use a StringBuffer object to build the String in the toString() method, calling zeroPad(int) as necessary.

Create a main method and construct the following times and print the time using System.out.println(clock):

Call the default constructor (no parameters)

hour: 12, minute: 94, second: 56

hour: 38, minute: 63, second: 64

hour: 98, minute: 76, second: -64

hour: 5, minute: 8, second: 1

hour: 23, minute: 59, second: 59

As required for all assignments from now on

validate the proper functionality using the example answers below and review the Concepts and Ideas checklist

format the code

Verify that the jar file contains source and class files and the MANIFEST.MF file contains a Main-Class. See the Resources section for Configuring Eclipse to view Jar files.

Run the application from the jar file, either from the command line using java -jar jarfilename or from Eclipse. See the Resources section for Configuring Eclipse to run Jar files.

submit the jar file in the Assignment section of BlackBoard under View/Complete Assignment for this assignment.

Method to Zero pad numbers to two places:

/** * Pad the values less than ten with zeroes on the left * @param value integer to pad with zeroes if necessary * @return zero padded string of the value parameter */ private String zeroPad (int value) { return String.format("%02d", value); }

Answers:

00:00:00 12:34:56 14:03:04 02:16:04 05:08:01 23:59:59

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

Students also viewed these Databases questions

Question

Describe mental toughness and its relationship to performance.

Answered: 1 week ago

Question

friendliness and sincerity;

Answered: 1 week ago