Hi I am trying to solve Zellers Congruence and I am having a little trouble. Here's my instructions:
1) Allow the user to enter a month. For calculation purposes, January = 1, February = 2, ... December = 12.
2) Enter a day of the month(1..31) Error checking is not necessary at this point, but would be helpful.
3) Enter a year using 4 digits (e.g., 1776, 1994, 2001)
4) Find the adjusted month and adjusted year
If the month entered is less than or equal to 2
Add 10 to it
Subtract 1 from the year entered
Otherwise
Subtract 2 from the month
Leave the year alone
5)Find the month correctionby
Multiplying the adjusted month by 26
Subtract 2 from the above
Integer divide the above by 10
6) Determine the century by integer dividing the adjusted year by 100
7)Determine the century remainder by finding the modulus 100 of the adjusted year
8)Determine the year correction by
Multiplying the century by five then
Adding the following to it
The century remainder
The century remainder integer divided by 4
The century integer divided by 4
9) Determine which weekday by
Adding the day, month correction, and year correction
Finding the above sum's modulus 7
If the solution to step 9 is '0', then the day is "Sunday". If it's '1', then the day is "Monday", ... if it's 6, then "Saturday".
So far i have this:
System.out.print("Enter the month (1-12): ");
int month = keyboard.nextInt();
System.out.println("Enter the day of the month (1-31):");
int day1 = keyboard.nextInt();
System.out.println("Enter a year (e.g, 1776,2003,2005):");
int year1 = keyboard.nextInt();
int adjustedMonth, adjustedYear, century, monthCorrection;
if (month <= 2)
{
adjustedMonth = month += 10;
adjustedYear=year1 -=1;
}
else
{
adjustedMonth = month-=2;
adjustedYear = year1;
}
//step 5
monthCorrection = (((adjustedMonth * 26) - 2) % 10);
century = adjustedYear % 100;
I am wondering if i am on the right track and if someone could help me guide the right way. I would appreciate it. So far i got up to step 6 of the instructions i was to do. Any help is great! Thank you!