Question

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

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**********\n");
       //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("\n");
       System.out.print("**********By Mohamed Diakite**********");
              

   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//pls provide +ve rating,thanks!!

=====================================

import java.util.*;

import javax.lang.model.util.ElementScanner6;

class Main {

public static void main(String[] args) {

//System.out.println("Hello world!");

//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**********\n");

//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();

}

//I changed you code from here ,CHEGGEA

int X,Y,Z,W,A,B,C,D;

B=dayOfMonth;

D=year/100;;

C=year;

if(month == 1)

{

A = 11;

C -= 1;

}

else if (month ==2)

{

A = 12;

     C -= 1;

}

else

{

A=month-2;

}

//calculate W,X,Y,Z and R by using algorithm given

C%=100;

D=year/100;

W = (13 * A - 1) / 5;

X = C / 4;

Y = D / 4;

Z = W + X + Y + B + C - 2 * D;

dayOfWeek = Z % 7;

if (dayOfWeek < 0)

{

dayOfWeek += 7;

}

//Up to here, CHEGGEA

//commented your code below..CHEGGEA

/*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 Sunday");

}

else if (dayOfWeek == 1) {

System.out.print("Day of the week is Monday");

}

else if (dayOfWeek == 2) {

System.out.print("Day of the week is Tuesday");

}

else if (dayOfWeek == 3) {

System.out.print("Day of the week is Wednesday");

}

else if (dayOfWeek == 4) {

System.out.print("Day of the week is Thursday");

}

else if (dayOfWeek == 5) {

System.out.print("Day of the week is Friday");

}

else if (dayOfWeek == 6) {

System.out.print("Day of the week is Saturday");

}

input.close();

System.out.println("\n");

System.out.print("**********By Mohamed Diakite**********");

}

}

===================================

//output1

**********Zeller's congruence**********

Enter year: eg 2012: 2019
Enter month: 1-12: 2
Enter the day of the month: 1-31: 18
Day of the week is Monday

//output2

**********Zeller's congruence**********

Enter year: eg 2012: 2019
Enter month: 1-12: 3
Enter the day of the month: 1-31: 12
Day of the week is Tuesday

//output3

**********Zeller's congruence**********

Enter year: eg 2012: 2018
Enter month: 1-12: 30
There are no more than 12 months in a year, try again
Enter month: 1-12: 12
Enter the day of the month: 1-31: 30
Day of the week is Sunday

//output4

**********Zeller's congruence**********

Enter year: eg 2012: 2018
Enter month: 1-12: 1
Enter the day of the month: 1-31: 31
Day of the week is Wednesday

Add a comment
Know the answer?
Add Answer to:
Zeller's congruence is an algorithm developed to calculate the day of the week. Write a program...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in python Worth 5 points (Science: day of the week) Zeller's congruence is an algorithm developed...

    in python Worth 5 points (Science: day of the week) 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). - is the day of the month. m is the month (3: March, 4: April, ...,...

  • Need help implementing this Java class (Science: day of the week) Zeller's congruence is an algorithm...

    Need help implementing this Java class (Science: day of the week) 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 + 5 * j) % 7 where h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4: Wednesday, 5: Thursday, 6: Friday). q...

  • USING PYTHON. (Science: day of the week) Zeller’s congruence is an algorithm developed by Christian Zeller...

    USING PYTHON. (Science: day of the week) 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, ...,...

  • Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender {...

    Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender { MyDate myDate; Day day; enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }    public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter date below :"); System.out.println("Enter day :"); int day = sc.nextInt(); System.out.println("Enter Month :"); int month = sc.nextInt(); System.out.println("Enter year :"); int year = sc.nextInt(); MyDate md = new MyDate(day, month, year); if(!md.isDateValid()){ System.out.println("\n Invalid date . Try...

  • Problem Description: Expand on 2 by implementing Insertion Sort and displaying the dates sorted after adding...

    Problem Description: Expand on 2 by implementing Insertion Sort and displaying the dates sorted after adding one to all dates. Run your code using the attached input files outputlong.txtoutputlab3.txt. Please note that your the dates that are sorted will be the ones after 1 day has been added to them. Sample Output: (green is user input) Run #2 using sample file outputlab3.txt Enter name of file to import or the word null to bypass: outputlab3.txt How many assessments in this...

  • How would you write the following program using switch statements instead of if-else statements (in java)...

    How would you write the following program using switch statements instead of if-else statements (in java) import java.util.*; public class ATM { public static void main(String[] args) { Scanner input = new Scanner (System.in); double deposit, withdrawal; double balance = 6985.00; //The initial balance int transaction; System.out.println ("Welcome! Enter the number of your transaction."); System.out.println ("Withdraw cash: 1"); System.out.println ("Make a Deposit: 2"); System.out.println ("Check your balance: 3"); System.out.println ("Exit: 4"); System.out.println ("***************"); System.out.print ("Enter Your Transaction Number "); transaction...

  • Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link...

    Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link to the file: CountAndAverageNumbers.javaPreview the document. Make sure you include comments in your code where errors were corrected. If you do not flag each error with a comment, points will be deducted. Upload the corrected .java file here. The output of the corrected file looks like the following: Debug4Output.PNG This program reads an unspecified number of integers, determines how many positive and negative values...

  • Open a new file in your text editor, and start a class that will demonstrate a...

    Open a new file in your text editor, and start a class that will demonstrate a working two-dimensional array: import java.util.Scanner; class TwoDimensionalArrayDemo { public static void main(String[] args) { 2. Declare a three-by-three array of integers. By default, the elements will all be initialized to 0. int[][] count = new int[3][3]; 3. Declare a Scanner object for input, variables to hold a row and column, and a constant that can be used to indicate when the user wants to...

  • (a)How many times does the code snippet given below display "Hello"? int x = 1; while...

    (a)How many times does the code snippet given below display "Hello"? int x = 1; while (x != 15) {    System.out.println ("Hello");    x++; } (b)What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 5) {    sum = sum + i;    i++; } System.out.println("The value of sum is " + sum); Quie 2 What is the output of the following snipped code? public class Test {...

  • Java programming 1. Write a program that reads an unspecified number of integers, determines how many...

    Java programming 1. Write a program that reads an unspecified number of integers, determines how many positive and negative value have been read, and computes the total and average of the input values (not counting zeros. Your program ends with the input 0. Display the average as a floating point number Here are sample runs: (red indicates a user input) Enter an integer, the input ends if it is 0: 1 2 -1 3 0 The number of positives is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT