Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class called Time that represents the time of the day. It has attributes for the hour and minute. The hour value ranges from

Write a class called Time that represents the time of the day. It has attributes for the hour and minute. The hour value ranges from 0 to 23, where the range 0 to 11 represents a time before noon. The minute value ranges from 0 to 59.

Write a default constructor that initializes the time to 0 hours and 0 minutes.

Write a private method isValid(hour, minute) that returns true if the given hour and minute values are in the appropriate range.

Write a method setTime(hour, minute) that sets the time if the given values are valid.

Write another method setTime(hour, minute, isAM)that sets the time if the given values are valid. The given hour should be in the range 1 to 12. The parameter isAM is true if the time is an a.m. time and false otherwise.

Add two more constructors that are similar to the setTime methods described.

Add a method getTime24 that returns a string that gives the time in 24 hour notation hhmm. For example,

If the hour value is 7 and the minute value is 25, return "'0725".

If the hour value is 0 and the minute value is 5, return "0005".

If the hour value is 15 and the minute value is 30, return "1530".

Add a method getTime12returns a string that gives the time in 12-hour notation h:mm xx. For example

If the hour value is 7 and the minute value is 25, return "7:25 am".

If the hour value is 0 and the minute value is 5, return "12:05 am".

If the hour value is 15 and the minute value is 30, return "3:30 pm".

Write a driver program to test your class and call it testTime.. Make sure to test all the 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

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions

Question

Everyone upstairs (receive, receives) mail before we do.

Answered: 1 week ago

Question

C&B Sales (is, are) listed in the directory.

Answered: 1 week ago