EasterSunday Class
/**
*An easter sunday will occur on a certain day of a certain month, which can be
*calculated based on the year.
*/
public class EasterSunday
{
private int year;
private int month;
private int day;
/**
*Creates a new easter sunday with year 0.
*/
public EasterSunday()
{
this(0);
}
/**
*Creates a new easter sunday with the year given.
*@param newYear Specifies the year.
*/
public EasterSunday(int newYear)
{
year=newYear;
Calc();
}
/**
*Calculates the month and day of easter sunday.
*/
private void Calc()
{
int a=year%19;
int b=year/100;int c=year%100;
int d=b/4;int e=b%4;
int g=(8*b+13)/25;
int h=(19*a+b-d-g+15)%30;
int j=c/4;int k=c%4;
int m=(a+11*h)/319;
int r=(2*e+2*j-k-h+m+32)%7;
month= (h-m+r+90)/25;
day=(h-m+r+month+19)%32;
}
/**
*Returns the month of easter.
*@return Returns the month.
*/
public String getMonth()
{
Month monthStr= new Month(month);
return monthStr.getMonth();
}
/**
*Returns the day of easter.
*@return Returns the day.
*/
public int getDay()
{
return day;
}
/**
*Returns All of the data.
*@return Returns all data.
*/
public String toString()
{
return "Easter will occur on day "+day+" of "+getMonth()+".";
}
}
/** output from demo
Enter the year: 2002
Easter will occur on day 31 of March.
Press any key to continue...
*/
Home