Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 2: The MyDate class (MyDate.java and MyDate_test.java) Description: Given the following UML, write a class called MyDate that represents a date consisting of a

image text in transcribed
image text in transcribed
Problem 2: The MyDate class (MyDate.java and MyDate_test.java) Description: Given the following UML, write a class called MyDate that represents a date consisting of a year, month, and day, and associated methods MyDate -year: int month: Int -day: int - MyDate() + MyDate(year-int, month:int, day:int) getDayO:int + getMonth():int + getYear(): int + addDays(days:int): vold + addWeeks(weeks int): void daysTo(other:MyDate); int +isleapYear(): boolean + toString(): String MyDate(): this non-argument Constructor will call the argument Constructor, and set the year to be 2000, month to be 1, and day to be 1. MyDate(int, int, int): this argument Constructor will create an MyDate object, and set the year, month and year to be a specific value. .getYear(); return the year value of this MyDate. .getMonth(); return the month value of this MyDate getDay();return the day value of this MyDate. addDays(int days): this method will move this MyDate object forward in time by the given number of days. For example, if the current date is 2020/2/28, if we add it by 3 days, it will become 2020/3/2 . addWeeks(int weeks): this method will move this MyDate object forward in time by the given number of seven-day weeks. For example, if the current date is 2020/3/7, if we add it by 2 weeks, it will become 2020/3/21. You can actually call the addDays() method, and add it by 14 days. daysTo(): this method returns the number of days that between this MyDate object to the other MyDate object. For example, the days from 2020/3/7 to 2020/4/1 is 25. .toString): will return the string representation of this MyDate object. For example: "2020/3/6". isLeapYear(): this is to judge whether the year of this MyDate object is a leap year or not. Return true if it is a leap year, otherwise return false. + Use the following criteria to judge a leap year: + If the year is divisible by 100 and at the same time also divisible by 400, it is a leap year. + If the year is not divisible by 100, but can be divisible by 4. It + addDays(days:int): void + addWeeks(week: int): void other:MyDate): int 5 of 8 bar(): boolean O: String MyDate(): this non-argument Constructor will call the argument Constructor, and set the year to be 2000, month to be 1, and day to be 1. MyDate(int, int, int): this argument Constructor will create an MyDate object, and set the year, month and year to be a specific value. .getYear(); return the year value of this MyDate. .getMonth(); return the month value of this MyDate .getDay();return the day value of this MyDate. addDays(int days); this method will move this MyDate object forward in time by the given number of days. For example, if the current date is 2020/2/28, if we add it by 3 days, it will become 2020/3/2 addWeeks(int weeks): this method will move this MyDate object forward in time by the given number of seven-day weeks. For example, if the current date is 2020/3/7. if we add it by 2 weeks, it will become 2020/3/21. You can actually call the addDays() method, and add it by 14 days daysTo(): this method returns the number of days that between this MyDate object to the other MyDate object. For example, the days from 2020/3/7 to 2020/4/1 is 25. .toString(): will return the string representation of this MyDate object. For example: "2020/3/6". . isleapYear(): this is to judge whether the year of this MyDate object is a leap year or not. Return true if it is a leap year. otherwise return false. + Use the following criteria to judge a leap year. + If the year is divisible by 100 and at the same time also divisible by 400, it is a leap year. + If the year is not divisible by 100, but can be divisible by 4. it is a leap year. + All others are not leap year. Once the definition of the MyDate class is done, write another java file as MyDate_test.java, to test its methods. Outputs: $java MyDate_test Please enter the year, month, and day of a MyDate: 202e 36 After adding 10 days, MyDate will be 2820 3 16 After adding 3 weeks, MyDate will be 2820 4 7 The days between 2020/3/6 and 2020/4/5 is 19 days. 2820/3/6 is at a leap year

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

Case Studies In Business Data Bases

Authors: James Bradley

1st Edition

0030141346, 978-0030141348

More Books

Students also viewed these Databases questions

Question

1.who the father of Ayurveda? 2. Who the father of taxonomy?

Answered: 1 week ago

Question

3. Would you say that effective teamwork saved their lives?

Answered: 1 week ago