Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Java class Clock for dealing with the day time represented by hours, minutes, and seconds. Your class must have the following features: Three

Write a Java class Clock for dealing with the day time represented by hours, minutes, and seconds. Your class must have the following features:

image text in transcribed

Three instance variables for the hours (range 0 - 23), minutes (range 0 - 59), and seconds (range 0 - 59). Three constructors: o default (with no parameters passed; should initialize the represented time to 12:0:0) o a constructor with three parameters: hours, minutes, and seconds. o a constructor with one parameter: the value of time in seconds since midnight it should be converted into the time value in hours, minutes, and seconds) Instance methods: o a set-method method setClock) with one parameter seconds since midnight (to be converted into the time value in hours, minutes, and seconds as above). o get-methods getHours(), getMinutes(, getSeconds with no parameters that return the corresponding values. o set-methods setHours(), setMinutes(), setSeconds() with one parameter each that set up the corresponding instance variables. o method tick) with no parameters that increments the time stored in a Clock object by one second. o method addClock() accepting an object of type Clock as a parameter. The method should add the time represented by the parameter class to the time represented in the current class. o Add an instance method toString() with no parameters to your class.toString() must return a String representation of the Clock object in the form "(hh:mm:ss)", for example "(03:02:34)". o Add an instance method tickDown which decrements the time stored in a Clock object by one second. o Add an instance method subtractClock() that takes one Clock parameter and returns the difference between the time represented in the current Clock object and the one represented by the Clock parameter. Difference of time should be returned as an clock object

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions

Question

4. Explain the strengths and weaknesses of each approach.

Answered: 1 week ago