Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ineed a short simple java code :) 3 1 Lab 09: Object Oriented Programming Objectives: - Putting Things together Exercise 1 A class called MyDate,

ineed a short simple java code :)
image text in transcribed
image text in transcribed
image text in transcribed
3 1 Lab 09: Object Oriented Programming Objectives: - Putting Things together Exercise 1 A class called MyDate, which models a date instance, is defined as shown in the class diagram. The MyDate class contains the following private instance variables: - year (int): Between 1 to 9999. Umm Al-Qura university 2019/2020 Computer \& Information Systems college instructor: Dr. Aymen M. Akremi - month (int): Between 1 (Jan) to 12 (Dec). - day (int): Between 1 to 28293031, where the last day depends on the month and whether it is a leap year for Feb (2829). It also contains the following private static variables (drawn with underlined in the class diagram): - strMonths (String[]), strDays (String[]), and dayInMonths (int[]): static variables, initialized as shown, which are used in the methods. The MyDate class has the following public static methods (drawn with underlined in the class diagram): - isleapyear(int year): returns true if the given year is a leap year. A year is a leap year if it is divisible by 4 but not by 100 , or it is divisible by 400 . - isvalidDate(int year, int month, int day): returnstrue if the given year, month, and day constitute a valid date. Assume that year is between 1 and 9999 , month is between 1 (Jan) to 12 (Dec) and day shall be between 1 and 28293031 depending on the month and whether it is a leap year on Feb. - getDayofweek(int year, int month, int day): returns the day of the week, where for Sun, 1 for Mon, ... 6 for Sat, for the given date. Assume that the date is valid. - The MyDate class has one constructor, which takes 3 parameters: year, month and day. It shall invoke setDate() method (to be described later) to set the instance variables. The MyDate class has the following public methods: - setDate(int year, int month, int day): It shall invoke the static method isvalidDate() to verify that the given year, month and day constitute valid date. (Advanced: Otherwise, it shall throw an IllegalArgumentException with the message "Invalid year, month, or day!" ) - setYear(int year): It shall verify that the given year is between 1 and 9999. (Advanced: Otherwise, it shall throw an IllegalArgumentException with the message "Invalid year!".) - setMonth(int month): It shall verify that the given month is between 1 and 12. (Advanced: Otherwise, it shall throw an IllegalArgumentException with the message "Invalid month!".) - setDay(int day): It shall verify that the given day is between 1 and daymax, where daymax depends on the month and whether it is a leap year for Feb. (Advanced: Otherwise, it shall throw an IllegalArgumentException with the message "Invalid month!".) Umm Al-Qura university Computer \& Information Systems college Instructor: Dr. Aymen M. Akremi - getYear(), getMonth(). getDay(): return the value for the year, month and day, respectively. - tostring(): returns a date string in the format "xxxday d mmm yyyy", e.g. "Tuesday 14 Feb 2012". - nextDay(): update this instance to the next day and return this instance. Take note that nextDay() for 31 Dec 2800 shall be 1 Jan 2801. - nextMonth(): update this instance to the next month and return this instance. Take note that nextMonth() for 31 Oct 2012 shall be 30 Nov 2012. - nextYear(): update this instance to the next year and return this instance. Take note that nextYear() for 29 Feb 2012 shall be 28 Feb 2013. (Advanced: throw an IllegalstateException with the message "Year out of range!" if year > 9999.) - previousDay(), previousMonth(), previousYear(): similar to the above. Write the code for the MyDate class. Use the following test statements to test the MyDate class

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

More Books

Students also viewed these Databases questions

Question

What is retribution?

Answered: 1 week ago

Question

1. Identify the sources for this conflict.

Answered: 1 week ago

Question

3. The group answers the questions.

Answered: 1 week ago