Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

I compiled it with no errors but when I run it I get oen error - incompatible types on this line

int day = dateFinder.getEasterSundayDay();

Any help would greatly be appreciated!

*********************************

package eastertester;

public class Easter

{

public Easter(int y)

{

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;

h = (19 * a + b -d - g + 15) % 30;

int j = c / 4;

int k = c % 4;

m = (a + 11 * h) / 319;

r = (2 * e + 2 * j - k - h + m + 32) % 7;

}

public int getEasterSundayMonth()

{

int n;

return n = (h - m + r + 90) / 25;

}

public int getEasterSundayDay(int n)

{

int p;

return p = (h - m + r + n + 19) % 32;

}

private int h;

private int m;

private int r;

}

******************************

package eastertester;

import java.util.Scanner;

public class EasterTester

{

public static void main(String[] args)

{

Scanner myScanner = new Scanner(System.in);

int year;

System.out.println("Please enter a year of your choice: ");

year = myScanner.nextInt();

Easter dateFinder = new Easter(year);

int month = dateFinder.getEasterSundayMonth();

int day = dateFinder.getEasterSundayDay();

System.out.print("In " + year);

System.out.println(", Easter is in month " + month);

System.out.println(" and on day " + day);

}

}

int day = dateFinder.getEasterSunday

Any help would greatly be appreciated!

**************************

package eastertester;

public class Easter

{

public Easter(int y)

{

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;

h = (19 * a + b -d - g + 15) % 30;

int j = c / 4;

int k = c % 4;

m = (a + 11 * h) / 319;

r = (2 * e + 2 * j - k - h + m + 32) % 7;

}

public int getEasterSundayMonth()

{

int n;

return n = (h - m + r + 90) / 25;

}

public int getEasterSundayDay(int n)

{

int p;

return p = (h - m + r + n + 19) % 32;

}

private int h;

private int m;

private int r;

}

**************************

package eastertester;

import java.util.Scanner;

public class EasterTester

{

public static void main(String[] args)

{

Scanner myScanner = new Scanner(System.in);

int year;

System.out.println("Please

year = myScanner.nextInt();

Easter dateFinder = new Easter(year);

int month = dateFinder.getEasterSunday

int day = dateFinder.getEasterSunday

System.out.print("In " + year);

System.out.println(", Easter is in month " + month);

System.out.println(" and on day " + day);

}

}

on the other hand the code you pasted wont compile because you dont pass a int to the getEasterSundayDay() method.

getEasterSunday(int) in eastertester.Easter cannot be applied to ()

incompatible types

found : eastertester.Easter.getEas

required int

What do you mean by

because you dont pass a int to the getEasterSundayDay() method.

Thank you for you time.

int day = dateFinder.getEasterSunday

the compiler founds that you must pass an int to this method, for example:

int day = dateFinder.getEasterSunday

I found the algorithm by Knuth on a web page (originally found in his book: "Fundamental Algorithms: The Art of Computer Programming, Vol. I" by Donald Knuth). And adjusted your Easter class based on it.

The problem is that you need to typecast the intermediate portions of the calculations to (int) otherwise you can either get inconsistent results or exceptions.

```
package eastertester;
public class Easter {
private int month;
private int day;
public Easter() {
month = 0;
day = 0;
}
public Easter(int y) {
month = 0;
day = 0;
calculateEaster(y);
}
public void calculateEaster(int y) {
int golden = (y % 19) + 1;
int century = (y / 100) + 1;
int solar = ((int) ((3 * century) / 4)) - 12;
int lunar = ((int) ((8 * century) + 5) / 25) - 5;
int sunday = ((int) ((5 * y) / 4)) + solar - 10;
int epact = (11 * golden + 20 + lunar - solar) % 30;
if ((epact == 24) || (epact == 25) && (golden > 11)) {
epact ++;
}
int fullMoon = 44 - epact;
if (fullMoon < 21) {
fullMoon = fullMoon + 30;
}
int easter = fullMoon + 6 - ((sunday + fullMoon) % 7);
if (easter > 31) {
month = 4; // april
day = easter - 31;
} else {
month = 3; // march
day = easter;
}
}
public int getEasterSundayMonth() {
return month;
}
public int getEasterSundayDay() {
return day;
}
}
```

```
package eastertester;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class EasterTester {
public static void main(String[] args) {
String year;
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
System.out.println("Please enter a year of your choice: ");
try {
year = in.readLine();
Easter dateFinder = new Easter(Integer.valueOf(year));
int month = dateFinder.getEasterSundayMonth();
int day = dateFinder.getEasterSundayDay();
System.out.print("In " + year);
System.out.print(", Easter is in month " + month);
System.out.println(" and on day " + day);
} catch (Exception e) {
}
}
}
```

I am supposed to have the program find the day and month when I put in a year.

So I change this:

public int getEasterSundayDay(int n)

if I take it out and replace it with this

public int getEasterSundayDay()

and now I getting error on this line

return p = (h - m + r + n + 19) % 32;

operator + cannot be applied to int, n

cammpt fomd symbol

symbol : variable n

location: class eastertester.Easter

operator % cannot be applied to <nulltype>,int

I appreciated the other code, however, this is an assignment and I have to do it this way.

I am a beginner and do not understand the error messages and only beginning to grasp the methods.

All the help is greatly appreciated.

return p = (h - m + r + n + 19) % 32;

Because you are no longer sending in the variable "n" as a parameter to the getEasterSundayDay method.

But, I am still curious where found the algorithm in the first place?

I tried to make those same program changes that you tried regarding the removal of the "n" parameter.

But, the result that came out of the program were incorrect.

All that was given was

Public int getEasterSundayDay()

{

Int p;

//Using step 10, compute and return the value of p. Note : This value (p) is the day that Easter falls on.

}

In the book it states

Divide h-m+r+n+19 by 32 to get remainder p. Ignore the quotient.

I am supposed to have the program find the day and month when I put in a year.

So I change this:

public int getEasterSundayDay(int n)

if I take it out and replace it with this

public int getEasterSundayDay()

and now I getting error on this line

return p = (h - m + r + n + 19) % 32;

operator + cannot be applied to int, n

cammpt fomd symbol

symbol : variable n

location: class eastertester.Easter

operator % cannot be applied to <nulltype>,int

I appreciated the other code, however, this is an assignment and I have to do it this way.

I am a beginner and do not understand the error messages and only beginning to grasp the methods.

If I take out "n" and run it

if complies

put the year of 1999

and give me answer of

In 1999, Easter is in month 4 and on day 0

So it has something to do with this line and the "n"

return p = (h - m + r + n + 19) % 32;

I hope I have not board you all

**************************

Exercise P3.17. Write a program to compute the date of Easter Sunday. Easter Sunday is the first Sunday after the first full moon of Spring. Use this algorithm, invented by the mathematician Carl Friedrich Gauss in 1800: 1.

Let y be the year (such as 1800 or 2001)

2.

Divide y by 19 and call the remainder a. Ignore the quotient.

3.

Divide y by 100 to get a quotient b and a remainder c

4.

Divide b by 4 to get a quotient d and a remainder e

5.

Divide 8 * b + 13 by 25 to get a quotient g. Ignore the remainder.

6.

Divide 19 * a + b - d - g + 15 by 30 to get a remainder h. Ignore the quotient.

7.

Divide c by 4 to get a quotient j and a remainder k

8.

Divide a + 11 * h by 319 to get a quotient m. Ignore the remainder.

9.

Divide 2 * e + 2 * j - k - h + m + 32 by 7 to get a remainder r. Ignore the quotient.

10.

Divide h - m + r + 90 by 25 to get a quotient n. Ignore the remainder.

11.

Divide h - m + r + n + 19 by 32 to get a remainder p. Ignore the quotient.

Then Easter falls on day p of 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 15. Write a class Year with methods getEasterSundayMonth and getEasterSundayDay.

Gauss's algorithm

This algorithm for calculating the date of Easter Sunday was first presented by the mathematician Carl Friedrich Gauss:

The number of the year is denoted by Y; mod denotes the remainder of integer division (e.g., 13 mod 5 a 3; see modular arithmetic). Calculate first a, b, and c:

a = Y mod 19

b = Y mod 4

c = Y mod 7

Then calculate

d = (19a + M) mod 30

e = (2b + 4c + 6d + N) mod 7

For the Julian calendar (used in Eastern churches), M = 15 and N = 6, and for the Gregorian calendar (used in Western churches), M and N are from the following table:

Years M N

15831699 22 2

17001799 23 3

18001899 23 4

19002099 24 5

21002199 24 6

22002299 25 0

If d + e < 10 then Easter is on the (d + e + 22)th of March, and is otherwise on the (d + e 9)th of April.

The following exceptions must be taken into account:

If the date given by the formula is 26 April, Easter is on 19 April.

If the date given by the formula is 25 April, with d = 28, e = 6, and a > 10, Easter is on 18 April.

[edit] Meeus/Jones/Butcher Gregorian algorithm

This algorithm for calculating the date of Easter Sunday is given by Jean Meeus in his book Astronomical Algorithms (1991), which in turn cites Spencer Jones in his book General Astronomy (1922) and also the Journal of the British Astronomical Association (1977). This algorithm also appears in The Old Farmer's Almanac (1977), p. 69. The JBAA cites Butcher's Ecclesiastical Calendar (1876).

The method is valid for all Gregorian years and has no exceptions and requires no tables.

Notation is as for the Gauss Algorithm above: all quotients are truncated to integers, thus 7 / 3 = floor(7 / 3) = 2 (not 2 1/3), and 7 mod 3 = 1.

Worked example

Year(Y) = 1961 Worked example

Year(Y) = 2008

a = Y mod 19 1961 mod 19 = 4 2008 mod 19 = 13

b = Y / 100 1961 / 100 = 19 2008 / 100 = 20

c = Y mod 100 1961 mod 100 = 61 2008 mod 100 = 8

d = b / 4 19 / 4 = 4 20 / 4 = 5

e = b mod 4 19 mod 4 = 3 20 mod 4 = 0

f = (b + 8) / 25 (19 + 8) / 25 = 1 (20 + 8) / 25 = 1

g = (b - f + 1) / 3 (19 - 1 + 1) / 3 = 6 (20 - 1 + 1) / 3 = 6

h = (19 × a + b - d - g + 15) mod 30 (19 × 4 + 19 - 4 - 6 + 15) mod 30 = 10 (19 × 13 + 20 - 5 - 6 + 15) mod 30 = 1

i = c / 4 6x1 / 4 = 15 8 / 4 = 2

k = c mod 4 61 mod 4 = 1 8 mod 4 = 0

L = (32 + 2 × e + 2 × i - h - k) mod 7 (32 + 2 × 3 + 2 × 15 - 10 - 1) mod 7 = 1 (32 + 2 × 0 + 2 × 2 - 1 - 0) mod 7 = 0

m = (a + 11 × h + 22 × L) / 451 (4 + 11 × 10 + 22 × 1) / 451 = 0 (13 + 11 × 1 + 22 × 0) / 451 = 0

month = (h + L - 7 × m + 114) / 31 (10 + 1 - 7 × 0 + 114) / 31 = 4 (April) (1 + 0 - 7 × 0 + 114) / 31 = 3 (March)

day = ((h + L - 7 × m + 114) mod 31) + 1 (10 + 1 - 7 × 0 + 114) mod 31 + 1 = 2 (1 + 0 - 7 × 0 + 114) mod 31 + 1 = 23

2 April 1961 23 March 2008

Change these two

**************************

public int getEasterSundayMonth() {

return (h - m + r + 90) / 25;

}

public int getEasterSundayDay(int month) {

return (h - m + r + month + 19) % 32;

{

**************************

and the tester

change this part

**************************

public int getEasterSundayDay(int month)

{

return (h - m + r + month + 19) % 32;

}

Also,

Thank you for going the extra mile.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.

Put that parameter back into the getEasterSundayDay method and in the Easter class, call it with:

int day = dateFinder.getEasterSunday

Then you will get the correct values.

Open in new window