Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A. (1 point) Write a minimal definition for a class named MyTime, about which you know nothing else (that is don't use the information in

image text in transcribed

A. (1 point) Write a minimal definition for a class named MyTime, about which you know nothing else (that is don't use the information in the following questions in this answer). Your answer to this question should be just the minimal definition - it will be really short! B. (2 points) Add a constructor for MyTime that takes an hour, a minute (of the appropriate primitive type), and a boolean that is true when the time is am, and false when the time is pm. The constructor should store these values in appropriately-named instance variables. If the hour or minute is invalid (hours should be from 1 to 12, and minutes should be from e to 59), then your constructor should throw an IllegalArgumentException. Your answer should be the entire class definition. C. (2 points) Add another constructor for MyTime that handles military time. It should take an hour and a minute (of the appropriate types). The constructor should inspect the hour, which will now be a value from 0 to 23 (this should be checked!), and convert it to an hour from 1 to 12, and an am boolean (as in part (B). For instance: an hour value of 1 will not change and am will be true an hour value of e should become 12 and am will be true an hour value of 19 should become 7 and am will be false an hour value of 24 should result in an IllegalArgumentException being thrown Your answer should be the entire class definition. D. (1 point) Write a public tostring() method with an appropriate signature that converts the MyTime object to a String representation as exemplified by "12:30 AM" or "4:32 PM" Your answer should be just the tostring() method

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

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

Have I incorporated my research into my outline effectively?

Answered: 1 week ago