Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Zeller's congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is h = ( q + (26(m

Zeller's congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is h = ( q + (26(m + 1 ) / 10 )) + k + (k/4) + (j /4) + (5j) ) % 7

where

h is the day of the week 0: Saturday 1 Sunday 2 Monday 3 Tuesday 4 Wednesday 5 Thursday 6 Friday

q is the day of the month

m is the month ( 3 March 4 April ... 12 December ) January and February are counted as months 13 and 14 of the previous year.

j is year / 100

k is the year of the century (i. e year % 100)

Note all divisions in this excerise perform an integer division. Write a program that prompts the user to enter a year, month, and day of the month, and displays the name of the day of the week.

Example from book:

Enter year (e.g 2012) : 2015

Enter month 1 -12 : 1

Enter the day of the month: 1 - 31: 25

Day of the week is Sunday.

Here is my work. I think I am not using remainder correctly.

import java.util.Scanner; public class DayOfTheWeek { public static void main(String[] arg) { // Create a scanner Scanner input = new Scanner(System.in); // Print out Enter the year System.out.println("Enter the year (e.g., 2012): "); double year = input.nextDouble(); // Print out Enter month System.out.println("Enter month 1-12: "); double month = input.nextDouble(); // Print out enter the day of month System.out.println("Enter the day of the month: 1- 31 "); double day = input.nextDouble(); // last part of formula from the right side to left ( formlast adds l for each left) double formlast = 5 * (year / 100); double formlastl = year / 4; double formlastll = (year % 100)/ 4; double k = year % 100; // bigthree is the division of the three including month double bigthree = ((26 * ( month + 1)) / 10); // add together to get h double h = (day + bigthree + k + formlastll + formlastl + formlast) % 7; System.out.println(h + " is the answer "); // if statement for day if ( h >= 0 && h < 1 ) System.out.println("Day of the week is Saturday! "); else if ( h >= 1 && h < 2 ) System.out.println("Day of the week is Sunday! "); else if (h >= 2 && h < 3 ) System.out.println("Day of the week is Monday! "); else if (h >= 4 && h < 5 ) System.out.println("Day of the week is Teusday! "); else if (h >= 6 && h < 7 ) System.out.println("Day of the week is Wednesday! "); else if (h >= 8 && h < 9 ) System.out.println("Day of the week is Thursday! "); else if (h >= 9 && h < 10 ) System.out.println("Day of the week is Friday! "); else System.out.println("Check and type again! "); } }

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

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Know how to find a consultant

Answered: 1 week ago

Question

Use service tiering to manage the customer base and build loyalty.

Answered: 1 week ago