Easter is observed by the churches of the West on the first Sunday following the full moon that occurs on or following the spring equinox (March 21). Easter is a "movable" feast which can occur as early as March 22 or as late as April 25.
Butcher's algorithm (see problem 7 on page 80 of the text) is a clever way of computing the day and month of Easter given the year:
class Butcher {
private int month;
private int day;
public int getDay() { return day; }
public int getMonth() { return month; }
public void calcEaster(int year) {
int a = year % 19;
int b = year / 100;
int c = year % 100;
int d = b / 4;
int e = b % 4;
int f = (b + 8)/25;
int g = (b – f + 1)/3;
int h = (19 * a + b – d – g + 15) %
30;
int i = c / 4;
int k = c % 4;
int l = (32 + 2 * e + 2 * i – h – k)
% 7;
int m = (a + 11 * h + 22 * l) / 451;
int p = (h + l – 7 * m + 114) % 31;
// now set fields
this.month = (h + l – 7 * m + 114) /
31;
this.day = p + 1;
}
}
Here's a test driver for this class:
Here's sample output generated by these classes:
enter a year -> 2008
Easter = 3/23/2008
enter a year -> 2009
Easter = 4/12/2009
enter a year -> 25
Easter = 4/6/25
enter a year -> -1
bye
Complete and test the implementation of Butcher.j.
Hints: You will need the putfield instruction to set the fields.