Programming Exercise 3.21 uses Zeller?s congruence to calculate the day of the week. Simplify Listing 6.12, PrintCalendar.java,
Question:
Programming Exercise 3.21 uses Zeller?s congruence to calculate the day of the week. Simplify Listing 6.12, PrintCalendar.java, using Zeller?s algorithm to get the start day of the month.
Listing
Transcribed Image Text:
Zeller's congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is 26(m + 1) 5j % 7 10 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. im is the month (3: March, 4: April, . 12: December). January and February are counted as months 13 and 14 of the previous year. year j is the century (i.e., 100 k is the year of the century (i.e., year % 100). Note that the division in the formula performs 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. Here are some sample runs: Enter year: (e.g., 2012): 2015 |Jtter Enter month: 1-12: 1 Ferte Enter the day of the month: 1-31: 25 utte Day of the week is Sunday Enter year: (e.g., 2012): 2012 ter Enter month: 1-12: 5 -Enter Enter the day of the month: 1-31: 12 Jenter Day of the week is Saturday 1 import java.util.Scanner; 3 public class PrintCalendar { /** Main method */ public static void main(String[] args) { Scanner input = new Scanner(System.in); // Prompt the user to enter year System.out.print("Enter full year (e.g., 2012): "); int year = input.nextInt(); 10 11 // Prompt the user to enter month System.out.print("Enter month as a number between 1 and 12: "); int month = input.nextInt(); 12 13 // Print calendar for the month of the year printMonth (year, month); 16 17 18 19 /** Print the calendar for a month in a year */ public static void printMonth(int year, int month) { // Print the headings of the calendar printMonthTitle(year, month); 21 22 23 24 // Print the body of the calendar printMonthBody Cyear, month); 25 26 27 28 29 /** Print the month title, e.g., March 2012 */ public static void printMonthTitle(int year, int month) { System.out.println(" " + year); System.out.println("- System.out.printInc" Sun Mon Tue Wed Thu Fri Sat"): 30 + getMonthName(month) 31 32 33 --"); 34 35 36 37 /** Get the English name for the month */ public static String getMonthName (int month) { String monthName = switch (month) { case 1: monthName = "January"; break; case 2: monthName = "February"; break; case 3: monthName = "March"; break; case 4: monthName = case 5: monthName = "May"; break; case 6: monthName case 7: monthName 38 39 40 41 42 "April"; break; 45 46 "June"; break; "July"; break; "August"; break; 47 48 49 50 case 8: monthName case 9: monthName = "September"; break; case 10: monthName = "October"; break; case 11: monthName - "November"; break; case 12: monthName = "December"; 51 52 53 54 55 56 57 58 return monthName; /** Print month body */ 111 111 222 222 222 233 333n33 m 444 444 45
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 52% (17 reviews)
This program displays month in a calendar when year and month are given as input To get the start da...View the full answer
Answered By
Branice Buyengo Ajevi
I have been teaching for the last 5 years which has strengthened my interaction with students of different level.
4.30+
1+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Write a program that uses the files described in Programming Exercise 12.31 and displays a ranking summary table for the first five girl?s and boy?s names as follows: The popularity ranking of baby...
-
Revise Programming Exercise 3.15 to add an additional $2,000 award if two digits from the user input are in the lottery number. Write a program that prompts the user to enter an integer for today?s...
-
Zeller?s congruence is an algorithm developed by Christian Zeller to calculate the day of the week. The formula is where ? h is the day of the week (0: Saturday, 1: Sunday, 2: Monday, 3: Tuesday, 4:...
-
Implement the method keys () for HashST.
-
Show that 3x4 + 1 is O(x4/2) and x4/2 is O (3x4+1).
-
Compare and contrast cornstarch with cotton balls, which are made of almost pure cellulose. Include at least three ways in which they are similar and three ways in which they are different. Mention...
-
Use the Hubble expansion relation (9.1.1), the temperature scaling relation (9.1.3), and the energy density relation before the electron-positron annihilation (9.3.6b) to show that the temperature as...
-
On October 1, Little Bobby Corporations stockholders equity is as follows. Common stock, $5 par value ............ $400,000 Paid-in capital in excess of parcommon stock ... 25,000 Retained earnings...
-
17. In many cases, a worker's hourly wage depends on the number of hours worked. If a certain number of hours is reached, the pay rate beyond that point increases. When working beyond a certain...
-
What is the solution of the recursive equation T (n) = 0.015625T +n?? (1/4) a) O(n') b) O(n' lg n) c) O(n* Ign) d) O(7*)
-
The area of a pentagon can be computed using the following formula: Write a method that returns the area of a pentagon using the following header:public static double?area(double?side)Write a main...
-
Invoking System.currentTimeMillis() returns the elapsed time in milliseconds since midnight of January 1, 1970. Write a program that displays the date and time. Here is a sample run: Current date and...
-
You have just purchased a car and taken out a $52,000 loan. The loan has a five-year term with monthly payments and an APR of 5.7%. a. How much will you pay in interest, and how much will you pay in...
-
What does (Perrow, 1984) describe as the etiology of organizational accident's five phases? What are the characteristics of strong safety culture (Pronovost et al. 2003)? Explain the benefits that...
-
A bullet travels at a speed of 390 m/s. Given that the speed of sound in air is 343 m/s, what is the bullet's Mach number M? Determine the bullet's Mach angle 0 in degrees. M = 0 =
-
Let X1, X2, ..., Xm denote an independent random sample from -01x f(x; 01) = 01e01, 0 x < and 0 > 0 and Y1, Y2, Yn denote an independent random sample from f(y; 02) = 02e-024 0yo and 02 > 0. The...
-
What are the merits and demerits of cooperative strategies?
-
How can executives implement strategies to nurture a corporate culture that not only embraces diversity and inclusion but also utilizes these components as drivers for enhanced team performance and...
-
What are the main differences in the 14 steps used to do non-statistical sampling for tests of details of balances versus for tests of controls and substantive tests of transactions?
-
The Higher the time period of the financial security the higher the. ............... risk. O a. Maturity O b. Default and Maturity Oc. Default O d. Liquidity
-
Rewrite Programming Exercise 7.15 using streams and sort the elements in the new array in increasing order. Data from Programming Exercise 7.15 Write a method that returns a new array by eliminating...
-
Rewrite Programming Exercise 7.17 using streams. Define a class named Student with data fields name and score and their getter methods. Store each student in a Student object. Data from Programming...
-
Rewrite Programming Exercise 20.1 using streams. Data from Programming Exercise 20.1 Write a program that reads words from a text file and displays all the words (duplicates allowed) in ascending...
-
Refer to the above Table 1. According to the information provided in the table, the 6-month yen is selling at a forward of approximately per annum. (Use the "mid rates" to make your calculations.)
-
Course: Professional Selling / Business Please Don't Copy/Paste. Answer the following questions- Q1. Background: You've had success at Stanley Black & Decker in your initial role as an Inside Sales...
-
In a kidnapping scenario, the kidnapper (Guy) would be inclined to kill the kidnappee (Orlando) if Orlando sees Guy's face, because if Orlando were released, he would be able to help the police...
Study smarter with the SolutionInn App