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% (19 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).
-
Look around your classroom, dormitory, or student organization. In what ways does it reflect cultural diversity? Suggest ways by which the resources represented in that diversity could be used to...
-
Mackey Company acquired equipment on January 1, 1996, through a leasing agreement that required an annual payment of $30,000. Assume that the lease has a term of five years and that the life of the...
-
Air containing 1.6 vol% sulfur dioxide is scrubbed with pure water in a packed column of 1.5-m2 cross-sectional area and 3.5-m height packed with no. 2 plastic Super Intalox saddles, at a pressure of...
-
4. Instagram, Inc. is a public corporation and has been one of the world's most active social networking sites. Its revenue is generated primarily from advertising: (a) Identify two internal users of...
-
Complete the function listmodn that, given an input list alist, an input value n, and an input index i, will attempt perform the modulo n operation on the i-th element of alist and return this value....
-
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...
-
Why is taxation of private property legal?
-
Taking a look at the current real estate development environment, please read: Tishman Speyer announced that it has acquired The Eddy, a recently-constructed, high-rise apartment tower located on the...
-
what ways do opportunities for career advancement and professional development influence your long-term job satisfaction ?
-
Identify two of the most important resources for product development in the telecommunication industry sector. Explain why you have identified these as most important
-
Diversification is a high-risk business development strategy. Define diversification and the reason this strategy is pursued by corporations. In your answer, outline questions to ensure corporations...
-
define research and development questions and prioritize them in a relation to contemporary managerial and business needs in details.
-
Think of three promises youve made to your family or friends today. Might they be enforceable in court? Why or why not?
-
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...
-
If you made a fixed deposit of $10,000 with an annual interest rate of 3% but the rate of inflation for that year is 3% as well, the calculation of Real Interest Rate would be like this
-
Miller Brothers Hardware paid an annual dividend of $1.80 per share last month. Today, the company announced that future dividends will be increasing by 3.20 percent annually. If you require a 9.5...
-
We know that possessing common stocks represents the corresponding ownership of that share of the companys assets. Suppose an investor buys 1% of equity of a levered firm, then her payoff will be A....
Study smarter with the SolutionInn App