Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do this in java [20 marks] Implement a Java method that prints out the day of the week for a given day (1. .

image text in transcribed

Please do this in java

[20 marks] Implement a Java method that prints out the day of the week for a given day (1. . . 31), month (1 . . . 12) and year in the range of March 1900 to February 2100.

Calculate the day of the week for the dates between March 1900 and February 2100 as follows:

First, you have to calculate the total number of days from 1900/1/1 to the given date (see below for details).

Secondly, you divide this number by 7 with an integer remainder: This now is the day of the week, with 0 as Sunday, 1 as Monday, and so on.

To calculate the total number of days, you have to implement the following steps:

Subtract 1900 from the given year, and multiply the result by 365

Add the missing leap years by adding (year 1900) / 4.

If the year itself is a leap year and the month is January or February, you have to subtract 1 from the previous result.

Now add all the days of the months of the given year to the result (in the case of February, it is always 28 because the additional day for a leap year has already been added in the calculation).

WeekDay - Attributes + private int numberOfDays + public static final int APRIL + public static final int AUGUST + public static final int DECEMBER + public static final int FEBRUARY + public static final int FRIDAY + public static final int JANUARY + public static final int JULY + public static final int JUNE + public static final int MARCH + public static final int MAY + public static final int MONDAY + public static final int NOVEMBER + public static final int OCTOBER + public static final int SATURDAY + public staic final int SEPTEMBER + public static final int SUNDAY + public static final int THURSDAY + public static final int TUESDAY + public static final int WEDNESDAY E Operations + public String getWeekDay (int day, int month, int 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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

LO2.2 List the main characteristics of the market system.

Answered: 1 week ago

Question

LO2.5 Describe the mechanics of the circular flow model.

Answered: 1 week ago