Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSC 2 0 5 Lab 2 Part I The Clock Class Creating our Very Own Class with Instance Methods - Clock Change into your Labs

CSC 205 Lab 2 Part I The Clock Class
Creating our Very Own Class with Instance Methods - Clock
Change into your Labs directory by typing cd Labs, and let us create and change into a Lab2
directory by typing mkdir Lab2 and then cd Lab2
Now, use your CalendarDate class as a guide to create a Clock class. Create a file named
Clock.java. Here, we want to create an instance class named Clock that contains the
following variables, methods, and constructors:
Private instance variables that store hours (0-23), minutes (0-59), and seconds (0-59).
A constructor that initializes the hours, minutes, and seconds to values specified by the
parameters.
A default constructor with no parameters that sets the hours, minutes, and seconds to 0.
A method named reset that resets the hours, minutes, and seconds to 0. It will have no
parameters.
An overloaded reset method that resets the hours, minutes, and seconds to values
specified by the parameters. It will have three parameters.
A method named advance that advances the clock by one second. If seconds has now
reached 60, reset seconds to 0, and increment the minutes. If, after incrementing minutes,
minutes has now reached 60, reset minutes to 0, and increment the hours. If, after
incrementing hours, hours has now reached 24, reset hours to 0.
A toString method that returns hours, minutes, and seconds as a string of the form
h:m:s
You should end up with a total of 6 public methods, and 3 private attributes. Compile your
Clock.java file before moving on to test it.
We now need to write a client program named TestClock that contains a main method that we
can use to test our class. In this client program, declare a Clock object named dvr. It will be
constructed using the default constructor. Next, prompt the user to input a specified hours,
minutes, and seconds. Reset your dvr object to this time using the reset method, print it out,
advance it by one second, and then reprint. Compile (javac TestClock.java) and run (java
TestClock. Heres a sample test case with the user input shown in boldface.
Note: if you have any errors in Clock.java, return to this file, make your changes and this file
will be automatically recompiled for you when you recompile TestClock.java.
What time would you like to set your DVR to?
Hours =23
Minutes =59
Seconds =59
The time is now 23:59:59
Advancing the time!
The time is now 00:00:00

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

More Books

Students also viewed these Databases questions

Question

Differentiate the function. r(z) = 2-8 - 21/2 r'(z) =

Answered: 1 week ago

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago