This assignment requires you to create a calendar program to calculate the day of week and the week of month for a given date, as well as to print the calendar as required.
/**
* CSIT/DPIT111 or CSIT811 Assignment 2
*
* Student name:
* Student user ID:
* Student number
*/
NOTE: Please indicate your subject code either CSIT/DPIT111 or CSIT811 as different requirements are assessed.
For a given date, we can use the Gregorian calendar to find the corresponding the day of the week, and the week of the month. For example, 19 October 2018 is a Friday and locates in the third week of October 2018.
In this assignment, you should use the following formula (Zeller's congruence) to calculate the day of a week for any given date after 15 October 1582.
h = (q + (13(m + 1) / 5) + K + (K/4) + (J/4) + 5J) mod 7,
where
NOTE: In this formula January and February are counted as months 13 and 14 of the previous year. e.g. if it is 2 February 2010, the algorithm counts the date as the second day of the fourteenth month of 2009.
For example, for 1 January 2000, the date would be treated as the 13th month of 1999, so the values would be: q=1, m=13, K=99, J=19, so the formula evaluates as
h = (1 + (13 * (13 + 1) . 5) + 99 + (99/4) + (19/4) + 5 * 19) mod 7
= (1 + (182/5) + 99 + (99/4) + (19/4) + 95) mod 7
= (1 + 36.4 + 99 + 24.75 + 4.75 + 95) mod 7
= (1 + 36 + 99 + 24 + 4 + 95) mod 7
= 0
which is a Saturday.
However, for 1 March 2000, the date is treated as the 3rd month of 2000, so the values become:q=1, m=3, K=0,J=20, so the formula evaluates as
h = (1 + (13 * (3 + 1) / 5) + 0 + (0/4) + (20/4) + 5 * 20) mod 7
= (1 + (52/5) + 0 + (0/4) + (20/4) + 100) mod 7
= (1 + 10.4 + 0 + 0 + 5 + 100) mod 7
= (1 + 10 + 0 + 0 + 5 + 100) mod 7
= 4
which is a Wednesday.
You may use any formula to determine the leap year.
You will create one program called MyCalendar.java. You should implement the MyCalendar and MyDate classes according to the following UML class diagrams.
You can add additional methods, but the existing attributes and methods cannot be modified.
MyCalendar
-----------------------
- myDate: MyDate
-----------------------
+ main(String[])
+ MyCalendar (MyDate)
+ getDayOfWeek(): Day
+ getWeekOfMonth(): int
+ printDateInfo(): void
+ printCalendar(): void
For example, for the date of 19 October 2018 it should print as
19/10/2018 is a Friday and located in the third week of October 2018
MyDate
------------------------
- day: int
- month: int
- year: int
------------------------
+ MyDate (int, int, int)
+ getDay(): int
+ getMonth(): int
+ get Year(): int
+ isDateValid(): boolean
The output format shown in this section is a formative part of the requirements that your program should comply with.
The following is a sample screenshot of running the correct and complete program that you can compare with your program.
(User input is in red colour, results in blue colour and prompt lines in black colour. Colours in this paper are for readability only. Your program does not need to print in colour.)
For CSIT/DPIT111 students:
Enter the date as day month year: 10 10 1582
Please enter a valid date
Enter the date as day month year: 29 2 2018
Please enter a valid date
Enter the date as day month year: 32 10 2018
Please enter a valid date
Enter the date as day month year: 19 10 2018
19/10/2018 is a Friday and located in the third week of October 2018
The calendar of October 2018 is:
SUN MON TUE WED THU FRI SAT
___ 1__ 2__ 3__ 4__ 5__ 6__
7__ 8__ 9__ 10_ 11_ 12_ 13_
14_ 15_ 16_ 17_ 18_ 19_ 20_
21_ 22_ 23_ 24_ 25_ 26_ 27_
28_ 29_ 30_ 31_