Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Description The goal for this assignment is to write a Class called GaussianEaster which will compute the month (m) and the day (d) of

Problem Description

The goal for this assignment is to write a Class called GaussianEaster which will compute the month (m) and the day (d) of a given year (Y) that corresponds to Easter. You will want to implement the algorithm inside of the Constructor for the GaussianEaster object. Remember not all variables mentioned in the algorithm need to be instance variables. Here is the algorithm that you will need to implement to compute (m) and (d):

First, calculate the location of the year Y in the Metonic cycle.

A = Y % 19;

Now, find the number of leap days according to Julian calendar.

B = Y % 4;

Then, lets take into account that the non-leap year is one day longer than 52 weeks

C = Y % 7;

M depends on the century of year Y. For 19th century, M = 23. For 21st century, M = 24 and so on. It is calculated using following relations:

P = (float) Math.floor (Y / 100) ; Q = (float) Math.floor ((13 + 8 * P) / 25) ;

M = (15 Q + P (P / 4)) % 30 ;

The difference between the number of leap days between the Julian and the Gregorian calendar is given by:

N = (4 + P (P / 4)) % 7;

The number of days to be added to March 21 to find the date of the Paschal Full Moon is given by:

D = (19*A + M) % 30;

And, the number of days from the Paschal full moon to the next Sunday is given by:

E = (N + 2*B + 4*C + 6*D) % 7 ;

int days = (int) (22 + D + E);

Therefore, using D and E, the date of Easter Sunday is going to be March (22 + D + E). If this number comes out to be greater than 31, then we move to April. Now the lunar month is not exactly 30 days but a little less than 30 days. So, to nullify this inconsistency, following cases are followed:

if (D == 29) and (E == 6) { // April 19

m = 4;

d = 19;

} else if (D == 28) and (E == 6) { // April 18

m = 4;

d = 18;

} else {

If (days > 31) {

d = days 31;

m = 4;

} else {

d = days;

m = 3;

}

}

Using the test year of 2001 shown in the book as input the output should look like:

Year: 2001 Month: 4 Day: 15

Getting Started

We are going to do this exercise by writing the object that solves the problem first (in a source file called GaussianEaster.java) and then testing it using code we write into Program.java. Using the techniques shown on the web page titled "How to Start Every Project in this Class" create a source file called GaussianEaster.java as well as a file called Program.java.

Open up the GaussianEaster.java file and replace the code with the code contained in the box below:

package edu.sbcc.cs105; /** * This class computes the month and day of Easter given the year. The only * instance variables allowed are m (the month) and d (the day). * */ public class GaussianEaster { public GaussianEaster(int y) { } public int getM() { } public int getD() { } } 

You should add comments to the code. This is especially relevant in the constructor because you should give a (very) brief explanation of the algorithm.

In Program.java, replace the code in that file with the code in the grey box below:

package edu.sbcc.cs105; import java.util.*; /** * This class tests the GaussianEaster object. * */ public class Program /** * Test this code by asking for a year and then having the GaussianEaster class compute the value. * * @param args * command line values. Not used in this example. */ public static void main(String[] args) { } }

You will also notice that Program.java does not contain any code to test the GaussianEaster.java source code. For your test code you can use this kind of prompt for input then output:

Input Easter year: 2001 Year: 2001 Month: 4 Day: 15

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

What is database?

Answered: 1 week ago

Question

What are Mergers ?

Answered: 1 week ago

Question

Where those not participating, encouraged to participate?

Answered: 1 week ago

Question

3. Who would the members be?

Answered: 1 week ago