Write a program to calculate the date of Easter Sunday. Easter Sunday is the first Sunday after the first full moon of spring. Use the algorithm invented by mathematician Karl Friedrich Gaus in 1800:
- Let
y be the year (e.g. 1800 or 2001). - Divide
y by 19 and call the remainder a . Ignore the factor. - Divide
y by 100 to get the coefficient b and the remainder c . - Divide
b by 4 to get the coefficient d and the remainder e . - Divide
8 * b + 13 by 25 to get the coefficient g . Ignore the rest. - Divide
19 * a + b - d - g + 15 by 30 to get the remainder h . ignore the factor. - Divide
c by 4 to get the coefficient j and the remainder k . - Divide
a + 11 * h by 319 to get the coefficient m . Ignore the rest. - Divide
2 * e + 2 * j - k - h + m + 32 by 7 to get the remainder r . Ignore the factor. - Divide
h - m + r + 90 by 25 to get the coefficient n . Ignore the rest. - Divide
h - m + r + n + 19 by 32 to get the remainder of p . Ignore the factor.
Easter then falls on day p month n .
For example, if y is 2001:
a = 6 b = 20 c = 1 d = 5 e = 0 g = 6 h = 18 j = 0 k = 1 m = 0 r = 6 n = 4 p = 15
Therefore, in 2001, Easter Sunday fell on April 15th.
Make sure you request the user for a year and enter the user in a year. Also, make sure that you display the p and n values with the appropriate messages describing the values displayed.
I am having a slight problem in putting this in Java code. Here is what I tried:
import java.util.Scanner; public class Easter { public static void main(String[] args) { Scanner input = new Scanner(System.in); int y = 2014; int a = y % 19; int b = y / 100; int c = y % 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; int n = (h - m + r + 90) / 25; int p = (h - m + r + n + 19) % 32; getEasterSundayMonth = n; System.out.println("Month: " + Easter.getEasterSundayMonth()); } }
This is what I have. I do not know how to assign the material, for example, I tried to get getEasterSundayMonth so that it getEasterSundayMonth value n , I am sure that it is not right. Where am I going from here?
source share