Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help implement these in Java Eclipse. Thanks Create the following classes. 1) Date with a) 3 private int fields: day, month, and hour. b) Public

Help implement these in Java Eclipse. Thanks

Create the following classes.

1) Date with

a) 3 private int fields: day, month, and hour.

b) Public access getters for all fields: They return the int values.

c) A single, public access constructor that takes the day, month, and year as parameters in that order. The constructor must validate all the three parameter values.

i) Year must be 1500 or more.

ii) Month must be between 1 and 12 (1 for January, 12 for December, etc.)

iii) Day (should be 1 or more) and checked to be consistent with the value in month. Examples: If month is 4 (April), day must be 30 or less. If month is 2 (February), day must be 28 or less for non-leap years. For a leap year, if month is 2 (February), day should be 29 or less. A year is a leap year if it is divisible by 4.

There is an exception though: If year is divisible by 100, it is a leap year if and only if it is divisible by 400. For examples: 2020 is a leap year because it is divisible by 4, but is not divisible by 100 1900 is not a leap year because it is divisible by 100, but not by 400. 2000 is a leap year because it is divisible by 400. 2021 is not a leap year because it is not divisible by 4

d) If one or more parameters values are incorrect, the Date constructor throws an Exception object with an appropriate String value (a message that indicates something is wrong with the parameters; it need not be very specific) passed to the Exception classs constructor.

e) The class should not have any other fields or constructors or public or protected or package access methods. You may have private methods, if you wish. And no overriding methods. If you override any method or put any other fields or method or constructor, those cannot be used in the other classes.

2) Time with

a) 2 private int fields: hour and minute.

b) Public access getters for both fields: They return the int values.

c) A public access constructor that takes the hour and minute as parameters in that order. The constructor must validate the two parameter values.

i) Legal vales for hour are 0 through 23.

ii) Legal vales for minute are 0 through 59.

If either parameter is incorrect, the Time constructor throws an Exception object with an appropriate String value (a message that indicates something is wrong with the parameters; it need not be very specific) passed to the Exception classs constructor.

d) The class should not have any other fields or constructors or public or protected or package access methods. You may have private methods, if you wish. And no overriding methods. If you override any method or put any other fields or method or constructor, those cannot be used in the other classes.

3) DateAndTime that uses a Date and Time object via composition appropriately. It should have a single, public constructor and a single public method named get(). You may have fields as appropriate for this problem.

a) The constructor must have the following parameters in the given order: hour, minute, day, month, and year.

b) The get() method should return a String object whose values must be consistent with the printout given below as output for the following code.

DateAndTime dateAndTime = new DateAndTime(14, 55, 28, 2, 2021);

System.out.println(dateAndTime.get());

14:55 hours on 28 February 2021

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

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions