Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with this homework problem Butcher\'s Algorithm to calculate Easter da

ID: 668520 • Letter: N

Question

Need help with this homework problem

Butcher's Algorithm to calculate Easter day for any year
in the Gregorian Calendar.

All values and calculations are integer only.

For a given year:

        a=year%19
        b=year/100
        c=year%100
        d=b/4
        e=b%4
        f=(b+8)/25
        g=(b-f+1)/3
        h=(19*a+b-d-g+15)%30
        i=c/4
        k=c%4
        x=(32+2*e+2*i-h-k)%7
        m=(a+11*h+22*x)/451
        Easter Month =(h+x-7*m+114)/31 [3=March, 4=April]
        p=(h+x-7*m+114)%31
Easter Date=p+1     (date in Easter Month)

Write a java program to prompt the user to enter a year.
Calculate and print the month and the day of Easter for that year.

Examples:

April 15, 1990
April 8, 2012
March 31, 2013

Explanation / Answer

/**The java program that prompts the user to enter the year value and then finds the easter date in the given
* year*/

//Easter.java

import java.util.Scanner;
class Easter
{
   public static void main(String[] args)
   {
       System.out.println("CALCULATION OF EASTER DATE");      

       //integer variable to read year value

       int year;
       Scanner scanner = new Scanner(System.in);
       System.out.print("PLEASE ENTER A YEAR : ");
       //read year from user
       year=scanner.nextInt();
      
       //check if the year is valid
       while(year <= 0)
       {
           System.out.println("ENTER A VALID YEAR");
           System.out.print("PLEASE ENTER A YEAR : ");
           year=scanner.nextInt();          
       }
       //call the metod
       System.out.print("EASTER DATE :");
       System.out.println(calculateEasterDate(year));
   }

   //The method calculateEasterDate that takes the year as input
   //and calculates the easter date and returns the string representation
   //of month and day in the given year.
   public static String calculateEasterDate(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 x=(32+2*e+2*i-h-k)%7;
       int m=(a+11*h+22*x)/451;
       int n=(h+x-7*m+114)/31;
       int p=(h+x-7*m+114)%31;
      

       String result;
       switch(n)
       {
       case 1:
           result = "January ";
           break;
       case 2:
           result = "February ";
           break;
       case 3:
           result = "March ";
           break;
       case 4:
           result = "April ";
           break;
       case 5:
           result = "May ";
           break;
       case 6:
           result = "June ";
           break;
       case 7:
           result = "July ";
           break;
       case 8:
           result = "August ";
           break;
       case 9:
           result = "September ";
           break;
       case 10:
           result = "October ";
           break;
       case 11:
           result = "November ";
           break;
       case 12:
           result = "December ";
           break;
       default:
           result = "error";
       }

       //return yester day.
       return result + (p+1);
   }//end of the method
  
}//end of the class


--------------------------------------------------------------------------------------------------------------------

Sample run1:

CALCULATION OF EASTER DATE
PLEASE ENTER A YEAR : 1990
EASTER DATE :April 15

Sample run2:

CALCULATION OF EASTER DATE
PLEASE ENTER A YEAR : 2012
EASTER DATE :April 8

Sample run3:

CALCULATION OF EASTER DATE
PLEASE ENTER A YEAR : 2013
EASTER DATE :March 31