Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started