Lavi M.

asked • 09/29/20

How to make a class called time on java with these data informaton:

■Class Time■

-second:int = 0 ----> hour:[o, 23]

--minute:int = 0 ----> minute: [o, 59]

-hour: int=0 -----> second: [e, 59]


Methods:-

+Time()

+Time (second: int, minute: int, hour: int)

+getHour): int

+getMinute() : int

+getSecond () : int

+setHour(hour: int): void

+setMinute (minute: int) : void

+setSecond (second: int) : void

+toString(): String-->"hh: mm: ss" with leading zero

+setTime (second: int, minute:int, hour: int) : void

+nextSecond (): Time -->increase by one second,and return this instance


****

A class called Time, which models a time instance with hour, minute and second, is designed as shown

in the class diagram. It contains the following members:-

1- 3 private instance variables hour, minute, and second.

2- Constructors, getters and setters.

3- A method setTime () to set hour, minute and second.

A toString() that returns "hh:mm: ss" with leading zero if applicable.

4- A method nextSecond () that advances this instance by one second. It returns this instance too

support chaining (cascading) operations, e.g, t1.nextSecond (). nextSecond (). Take note that

the nextSecond() of 23:59:59 is 00:00:00.

Write the Time class and a test driver to test all the public methods. No input validations are required.




1 Expert Answer

By:

Patrick B. answered • 09/29/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.