Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Zeller's congruence is an algorithm developed to calculate the day of the week. Write a program that prompts the user to enter a year, month,

Zeller's congruence is an algorithm developed to calculate the day of the week. Write a program that prompts the user

to enter a year, month, day of month and it displays the name of the week.

Here is my source code. I need it broke down into a flowchart.

public static void main(String[] args) { //all variables are initialized to 0, because local variables require at least an initial value before use Scanner input = new Scanner(System.in); // creation of scanner object for user input int year = 0, month = 0; // variables for collecting user input int k = 0, j = 0, dayOfWeek = 0, dayOfMonth = 0;; // j = century, k = year of century System.out.println("**********Zeller's congruence********** "); //System.out.println(); System.out.print("Enter year: eg 2012: "); year = input.nextInt(); System.out.print("Enter month: 1-12: "); month = input.nextInt(); while (month > 12) { System.out.println("There are no more than 12 months in a year, try again"); System.out.print("Enter month: 1-12: "); month = input.nextInt(); } System.out.print("Enter the day of the month: 1-31: "); dayOfMonth = input.nextInt(); while (dayOfMonth > 31) { System.out.println("There is never more than 31 days in a month, try again"); System.out.print("Enter the day of the month: 1-31: "); dayOfMonth = input.nextInt(); } k = year % 100; j = year / 100; if (month <= 2) { month += 12; } dayOfWeek = dayOfMonth + 26 * (month + 1) / 10 + k + k / 4 + j / 4 + 5 * j; dayOfWeek = dayOfWeek % 7; if (dayOfWeek == 0) { System.out.print("Day of the week is Friday"); } else if (dayOfWeek == 1) { System.out.print("Day of the week is Saturday"); } else if (dayOfWeek == 2) { System.out.print("Day of the week is Sunday"); } else if (dayOfWeek == 3) { System.out.print("Day of the week is Monday"); } else if (dayOfWeek == 4) { System.out.print("Day of the week is Tuesday"); } else if (dayOfWeek == 5) { System.out.print("Day of the week is Wednesday"); } else if (dayOfWeek == 6) { System.out.print("Day of the week is Thursday"); } input.close(); System.out.println(" "); System.out.print("**********By Mohamed Diakite**********");

}

}

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

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

1. What are your creative strengths?

Answered: 1 week ago

Question

What metaphors might describe how we work together?

Answered: 1 week ago