master
Learning Profile for Assignment #2, And Question #6
Name: Mo Khan Student ID: 3431709
- Problem Statement:
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:
1. Calculate the total number of days from 1900/1/1 to the given date (see below for details).
1. 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:
1. Subtract 1900 from the given year, and multiply the result by 365
1. Add the missing leap years by adding (year − 1900) / 4.
1. If the year itself is a leap year and the month is January or February, you have to subtract 1 from the previous result.
1. 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).
- Description of the Code:
The code implements the algorithm described above. It attempts to validate the entered day, month and year. It assumes that the entered input is an integer value. The bounds of the input is January 1900 to February 2100.
-
Errors and Warnings:
-
When the year is less than 1900, then an error is displayed.
```bash
$ java -cp target/assignment2*.jar ca.mokhan.comp268.App 6
--- Question 6 ---
Enter year:
1899
Invalid year.
```
- When the year is greater than 2100, then an error is displayed.
```bash
$ java -cp target/assignment2*.jar ca.mokhan.comp268.App 6
--- Question 6 ---
Enter year:
2101
Invalid year.
```
- When the year is 1900 and the month is before March, then an error is displayed.
```bash
$java -cp target/assignment2*.jar ca.mokhan.comp268.App 6
--- Question 6 ---
Enter year:
1900
Enter month:
2
Invalid month.
```
- When the year is 2100 and the month is after February, then an error is displayed.
```bash
$ java -cp target/assignment2*.jar ca.mokhan.comp268.App 6
--- Question 6 ---
Enter year:
2100
Enter month:
3
Invalid month.
```
-
Sample Input and Output:
-
March 1, 1900 was a Thursday.
```bash
$ java -cp target/assignment2*.jar ca.mokhan.comp268.App 6
--- Question 6 ---
Enter year:
1900
Enter month:
3
Enter day:
1
Today is:
Thursday
```
- January 31, 2100 will be on a Sunday.
```bash
$ java -cp target/assignment2*.jar ca.mokhan.comp268.App 6
--- Question 6 ---
Enter year:
2100
Enter month:
1
Enter day:
31
Today is:
Sunday
```
- Discussion: