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, ...,...

  • Let's update our program, SalaryCalcLoop.java, from last week, to now take input about each employee from...

    Let's update our program, SalaryCalcLoop.java, from last week, to now take input about each employee from a file and write their information and salary/pay information to a file. Rashid night 60 20 Chin day 30 15 Tran day 45 10 Deeshan night 55 11.5 Serena day 24 10 Deepak day 66 12 Tyrone night 11 18 Andre night 80 15 import java.util.Scanner; import java.io.*; import java.io.FileWriter; import java.util.NoSuchElementException; public class SalaryCalcLoop{ double pay=0, OTpay=0; void gpay(double hours, double wage){ if...

  • 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...

  • Modify the virtual translator program: virtual.java Modify it so it loops ten times asking the user...

    Modify the virtual translator program: virtual.java Modify it so it loops ten times asking the user for the ten virtual address from the work sheet we did the week before spring break. Once you have it working run it in a script command capturing the output. Make sure the script file has a .txt extension and upload the output. //Java Program import java.util.Scanner; public class virtual{    public static void main(String[] args){    int[] virtualAddressPace={2,1,6,0,4,3,-1,-1,-1,5,-1,7,-1,-1,-1,-1};    Scanner input = new...

  • 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...

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