0% found this document useful (0 votes)
140 views3 pages

Exercise 4: Easter: Goals of This Exercise

The document describes an exercise to design and implement functions in Java to calculate dates of Christian holy days that depend on the date of Easter for a given year. It includes functions to determine if a year is a leap year, get the number of days in a month, calculate the date of Easter, and display the dates of holy days and a calendar for the full year.

Uploaded by

Tjalle Wolterink
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views3 pages

Exercise 4: Easter: Goals of This Exercise

The document describes an exercise to design and implement functions in Java to calculate dates of Christian holy days that depend on the date of Easter for a given year. It includes functions to determine if a year is a leap year, get the number of days in a month, calculate the date of Easter, and display the dates of holy days and a calendar for the full year.

Uploaded by

Tjalle Wolterink
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Exercise 4: Easter

September 22, 2020

Goals of this exercise


After doing this assignment you are able to:
• create and use parameterized functions that may return a value of standard elementary
data type, viz. boolean, int, double, char, String;
• structure your program by means value-returning, parameterized functions.

Preparations
In this assignment you design and implement a program that computes the dates of a number
of Christian holy days that depend on the date of Easter. It is not allowed to use the java JRE date
manipulating classes like Calendar, Date etc!
• On Brightspace you find a project easter.zip that already contains the signatures of the
functions that you need to develop. Import this file with IntelliJ.

Part 4.1: Leap years


When calculating with dates, you need to take leap years into account. A year is a leap year if its
year number is dividable by 4, except if it is a multiple of 100 that is not dividable by 400. Hence,
1600 is a leap year, but 1700 is not a leap year. In a leap year February has 29 days instead of 28.
For completeness we summarize the months and their number of days:
Month #days Month #days Month #days
January 31 May 31 September 30
February 28 (29 in a leap year) June 30 October 31
March 31 July 31 November 30
April 30 August 31 December 31
Scenario:
• Experiment with the following years and answer with yes or no whether they are leap
years: 1900, 1999, 2000, 2012, 2013, 2014, 2015, 2016.
• Design and implement the parameterized function isLeapYear that has the signature:

public static boolean isLeapYear(int year)

It returns true only if the argument year is a leap year, and it returns false otherwise.
• Design and implement the parameterized function numberOfDaysInMonth that has the
signature:

public static int numberOfDaysInMonth(int year, Month month)

Note that the data type Month is already defined as an enumeration type in your project.

1
Part 4.2: Holy days based on Easter
The dates of several Christian holy days depend on Easter in the following way:

• Carnival (carnaval): 7 weeks before Easter, ending on Tuesday.


• Good Friday (Goede Vrijdag): Friday before Easter.
• Ascension Day (Hemelvaart): 10 days before Whitsuntide.

• Whitsuntide (Pinksteren): 7 weeks after Easter.


Easter is on the first Sunday after the first full moon on or after the beginning of spring (March
21). The Meeus/Jones/Butcher formula computes the Easter date (month, day) for a year (Y):
a = Y mod 19
b = Y / 100
c = Y mod 100
d = b / 4
e = b mod 4
f = (b + 8) / 25
g = (b - f + 1) / 3
h = (19 * a + b - d - g + 15) mod 30
i = c / 4
k = c mod 4
L = (32 + 2 * e + 2 * i - h - k) mod 7
m = (a + 11 * h + 22 * L) / 451
month = ( h + L - 7 * m + 114) / 31
day = ((h + L - 7 * m + 114) mod 31) + 1
This computation is based on the so-called Metonic cycle which consists of 19 years. It is impor-
tant to observe that all computations are integer operations. Design and implement a function
showHolyDays that allows a user to enter a year Y and which prints the dates (month, day) of
all of the above mentioned holy days (including Easter) for that year Y.
Scenario:
• Design and implement the functions easterMonth and easterDay that compute the day
and month respectively of Easter given a year as int-parameter. Hence, the signatures are:

static Month easterMonth(int year)


static int easterDay(int year)

• Design and implement the function dayNumberInYear that computes what the day num-
ber is of a given date (day/month/year) in that year. The signature is:

static int dayNumberInYear(int day, Month month, int year)

For instance, the number of the first of January is always 1, and the number of the first of
March in a leap year is 61, and it is 60 in non-leap years.
• Design and implement the functions monthInYearOfDayNumber and
dayInMonthOfDayNumber that compute for a given day number in a given year the cor-
responding month, and day in month. The signatures are:

static Month monthInYearOfDayNumber(int dayNumber, int year)


static int dayInMonthOfDayNumber(int dayNumber, int year)

2
For instance, the month of day number 60 in a leap year is February, whereas the month of
day number 60 in a non-leap year is March. Consequently, the day in month of day number
60 in a leap year is 29 (February), and it is 1 (March) in a non-leap year.
• Design and implement the function showHolyDays, using the above created functions.
The signature of this function is:

static void showHolyDays(int year)

Part 4.3: Display a year calendar


Design and implement the function showYear, that is parameterized with a year, that shows the
complete year in a way that is customary in calendars. Weeks start on Sunday. For example, the
expected output of 2020 should be:
2020
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5 6 7
5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31

April May June


Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 2 1 2 3 4 5 6
5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
31

July August September


Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5
5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12
12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19
19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26
26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30
30 31

October November December


Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5
4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12
11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19
18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26
25 26 27 28 29 30 31 29 30 27 28 29 30 31

You might also like