Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer as soon as possible. Using Java create the following classes below. Date class Create a Date class with instance variables, constructor arguments, setters

Please answer as soon as possible.

Using Java create the following classes below.

Date class

Create a Date class with instance variables, constructor arguments, setters and getters for three int variables: day, month, and year. Also create a method named public String getDayOfTheWeek() which calculates and returns the name of the day of the week (e.g. "Wednesday") for the object's day, month, and year.

Date classs public String getDayOfWeek() method algorithm: Add the following to your Date class. The method signature must be: public String getDayOfTheWeek()

This method returns the day of the week (e.g. "Wednesday") for a specified date (e.g. October 31, 2012).

It must make use of a private method whose method signature is: private boolean isLeapYear() (see: http://en.wikipedia.org/wiki/Leap_year)

Which returns true (e.g. for 1996, 2000, 2012, etc) or false (e.g. for 1900, 2011, etc) depending on whether a year is a leap year or not.

Here is the algorithm to determine what day of the week a given date is:

Example dates: August 16, 1989 and March 20, 1950

Step 1: Only look at the last two digits of the year and determine how many 12s fit in it

7 12s in 89 4 12s in 50

Step 2: Look at the remainder of this division:

89 7 * 12 = 5 50 4 * 12 = 2

Step 3: How many 4s fit into that remainder:

1 four in 5 0 fours in 2

Step 4: Add the day of the month:

16 for the 16th 20 for the 20th

Step 5: Add the month code:

3 for August 4 for March

Jan = 1

Feb = 4

Mar = 4

Apr = 0

May = 2

Jun = 5

Jul = 0

Aug = 3

Sep = 6

Oct = 1

Nov = 4

Dec = 6

Step 6: Add all of the above numbers, then mod by 7:

7 + 5 + 1 + 16 + 3 = 32 4 + 2 + 0 + 20 + 4 = 30 32 % 7 = 4 30 % 7 = 2

This is your day of the week, as follows:

Sat = 0

Sun = 1

Mon = 2

Tue = 3

Wed = 4

Thu = 5

Fri = 6

August 16, 1989 March 20, 1950 Wednesday Monday

NOTE: some dates require special offsets:

January and February dates in leap years: subtract 1 from step 5

Dates in the 1600s: add 6 to step 5 Dates in the 1700s: add 4 to step 5 Dates in the 1800s: add 2 to step 5 Dates in the 2000s: add 6 to step 5 Dates in the 2100s: add 4 to step 5

Test your Date class to make sure it works properly.

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

1st Edition

1597496251, 978-1597496254

More Books

Students also viewed these Databases questions

Question

2. Discuss the steps in preparing a manager to go overseas.

Answered: 1 week ago