Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Start a new file called Clock.java. Write a class called Clock. Here are the first few lines: public class Clock { // instance variables

JAVA Start a new file called Clock.java.

Write a class called Clock. Here are the first few lines: public class Clock { // instance variables private int hour; private int minute; private int second;

Write a default constructor for a 12-hour Clock that initializes hour to one, minute to zero, and second to zero. The constructor should not have assignment statements. It should call the mutators for hour, minute, and second.

Write accessors and mutators for all instance variables (6 methods total, 3 accessors and 3 mutators). The mutators should perform data validation. Valid hour 1 - 12. Valid minute 0 - 59. Valid second 0 - 59.

Write a toString method that will return a String representation of a Clock object using the format hour : minute : second Each integer should occupy 2 digits. (hint: use the String.format method) For example, if hour contains 12, minute contains 5, and second contains 9, the toString method should return the String "12:05:09".

Write a method called tick that will increment the number of seconds, then adjust the minute and hour, if needed. The method does not return a value.

Write an equals method that will return true if the Clock parameter has the same hour, minute, and second as the calling object.

Compile Clock.java. Debug any syntax errors before you go on.

Start a new file called ClockTest.java. This is the test (driver) program for the Clock class so it should have a main method. Write sufficient statements in the main method to thoroughly test all of the methods in the Clock class. (There are 10 methods.)

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions