Rewrite the PrintCalendar class in Listing 6.12 to display a calendar for a specified month using the
Question:
Rewrite the PrintCalendar class in Listing 6.12 to display a calendar for a specified month using the Calendar and GregorianCalendar classes. Your program receives the month and year from the command line. For example:java Exercise13_04 5 2016This displays the calendar shown in Figure 13.9.
The program displays a calendar for May 2016.
You also can run the program without the year. In this case, the year is the current year. If you run the program without specifying a month and a year, the month is the current month.
Listing
Transcribed Image Text:
0a. Command Prompt c:\exercise>java Exercise13_04 5 2016 May, 2016 Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 10 11 12 13 14 19 20 21 15 16 17 18 23 24 27 28 25 26 29 30 31 C:\exercise> 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(); 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 14 15 // 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); 20 21 22 // Print the body of the calendar printMonthBody(year, 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.println(" Sun Mon Tue Wed Thu Fri Sat"); 30 31 32 + getMonthName (month) 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 = 38 39 40 41 "January"; break; "February"; break; "March"; break; "April"; break; "May"; break; "June"; break; 42 case 2: monthName case 3: monthName - case 4: monthName case 5: monthName = case 6: monthName case 7: monthName = "July"; break; case 8: monthName case 9: monthName case 10: monthName = "October"; break; case 11: monthName = "November"; break; case 12: monthName = "December"; 43 44 45 46 47 48 "August"; break; "September"; break; 49 50 51 52 53 54 55 return monthName; 56 57 58 /** Print month body */ HNm S67 0090 1234 567 c0 9C m45 67 00 0 O12 m4Se 7 00 90 222 22~ 233 mmm m3m 3
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 80% (10 reviews)
Program Plan 1 Create a class DisplayCalendars 2 Declare and Initialize the Calendar object with the ...View the full answer
Answered By
Madhur Jain
I have 6 years of rich teaching experience in subjects like Mathematics, Accounting, and Entrance Exams preparation. With my experience, I am able to quickly adapt to the student's level of understanding and make the best use of his time.
I focus on teaching concepts along with the applications and what separates me is the connection I create with my students. I am well qualified for working on complex problems and reaching out to the solutions in minimal time. I was also awarded 'The Best Tutor Award' for 2 consecutive years in my previous job.
Hoping to get to work on some really interesting problems here.
5.00+
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
-
Rewrite the Course class in Listing 10.6 to add a clone method to perform a deep copy on the students field. Listing 1 public class Course { private String courseName; private String[] students = new...
-
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...
-
Listing 2.7, ShowCurrentTime.java, displays the current time. Improve this example to display the current date and time. The calendar example in Listing 6.12, PrintCalendar.java, should give you some...
-
An automobile is traveling at 60.0 km/h. Its tires have a radius of 33.0 cm. (a) Find the angular speed of the tires (in rad/s). (b) Find the angular displacement of the tires in 30.0 s. (c) Find the...
-
A functional f is quasiconvex if and only if every lower contour set is convex; that is, is convex for every a . {xe X:f(x) < c} 3,(c) =
-
Graph each function in Problems 4752. h(x) = 10 + 2x 40+0.5x if 0 x 20 if x > 20
-
What are the two categories of data mining and knowledge discovery software?
-
In Kagan Company, materials are entered at the beginning of each process. Work in process inventories, with the percentage of work done on conversion costs, and production data for its Sterilizing...
-
Accounting information systems collect and process information from transactions and then organizes it into useful information for company management and typically include the general journal, which...
-
The Modigliani-Miller theorem assumes that the firm has only two classes of securities, perpetual debt and equity. Suppose that the firm has issued a third class of securities-preferred stock-and...
-
Modify the GeometricObject class to implement the Comparable interface, and define a static max method in the GeometricObject class for finding the larger of two GeometricObject objects. Draw the UML...
-
Rewrite the Rectangle class in Listing 13.3 to extend GeometricObject and implement the Comparable interface. Override the equals method in the Object class. Two Rectangle objects are equal if their...
-
What is the typical amount of main store, cache, and hard disk provided by current high-performance, state-of-the-art, cutting-edge personal computers?
-
Suppose that a man and a woman each choose whether to go to a prize fight or a ballet. The man would rather go to the prize fight, and the woman to the ballet. What is more important to them,...
-
Briefly describe the difference between the 3 levels of the fair value hierarchy that a company following IFRS must choose from when noting its ability to reliably measure each investment's fair...
-
In which situations would you most likely choose to implement a Type 1 hypervisor as opposed to a Type 2? When you want to use VMware's ESXi as your virtualization platform When your host systems are...
-
Harold earns a salary of $200,000 from EMK enterprises as an officer during this year for the first 11 months of the year. Harold withholds OASDI (Social Security) taxes in the amount of $9,932.40....
-
A U.S. company purchases a 90-day certificate of deposit from a Singapore bank on May 15, when the spot rate is $0.72/S$. The certificate has a face value of S$100,000 and pays interest at an annual...
-
Erin Carson, Megyn Delaney, and Caitlin Erikson form a partnership as a first step in creating a business. Carson invests most of the capital but does not plan to be actively involved in the...
-
Explain the buyers position in a typical negotiation for a business. Explain the sellers position. What tips would you offer a buyer about to begin negotiating the purchase of a business?
-
In the method header public static boolean(int age), age is a(n) _____. a. Argument b. Parameter c. Return value d. Final value
-
Which of the following method declarations is correct for a static method named computeSum() if the method receives two double arguments? a. Public static double, double computeSum() b. Public static...
-
Which of the following method declarations is correct for a static method named display Facts() if the method receives an int argument? a. Public static int display Facts() b. Public void display...
-
The city of Austin needs to collect $2,000,000 in property tax revenues. The city estimates 5% of the tax revenues will not be collectible. How much in tax levies should the city of Austin for the...
-
A bakery corporation earns a total revenue of $157,000. Its expenses are $52,000. If the bakery needs to pay 21% corporate income tax, how much tax will they pay? Show your calculations.
-
Year 1: Chip Corp had taxable income before taking a charitable contribution deduction of $25000. They made $4,000 in charitable donations that year. Year 2: Chip Corp had taxable income before...
Study smarter with the SolutionInn App