Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Intro to Java Programming chapter 13 problem 4 Listing 6.12 Printcalendar.java 1 import java.util.scanner 3 public class Printcalendar 4 IMain method/ 5 public static void
Intro to Java Programming chapter 13 problem 4
Listing 6.12 Printcalendar.java 1 import java.util.scanner 3 public class Printcalendar 4 IMain method/ 5 public static void main(Stringt] args) Scanner input new Scanner (System.in) // Prompt the user to enter year System.out.print("Enter full year (e.g., 2012)") int yearinput.nextInt) 10 // 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 16 17 18 19 20Print the calendar for a month in a year/ 21 public static void printMonth(int year, int month) // Print calendar for the month of the year printMonth(year, month) printMonth // Print the headings of the calendar printMonthTitle(year, month)i 23 24 25 26 27 28 29 30 31 32 // Print the body of the calendar printMonthBody (year, month) Print the month title, e.g., March 2012 public statie void printMonthTitle(int year, int month) System.out.println("getMonthName (month) printMonthTitle +year) System.out.println( System.out.printin(" Sun Mon Tue Wed Thu Pri Sat") 34 35 36 37 Get the English name for the month/ 38 public static string getMonthName (int month) 39 40 41 4 2 43 getMonthName String monthName switch (month) 45 4 6 47 4 8 49 50 51 52 53 54 case 1: monthName "January" break; case 2: monthName "February": break case 3: monthName"March"; break; case 4: monthName"April"; break; case 5: monthName "May" break; case 6: monthName"June"; break; case 7: monthName "July" break; case 8: monthName"August"break; case 9: monthName"September"break case 10: monthName "October" break; case 11: monthName "November" break; case 12: monthName"December" return monthName; 56 57 58 Print month body printMonthBody 59 public static void printMonthBody(int year, int month) // Get start day of the week for the first date in the month int startDaygetstartDay (year, month); 60 61 62 63 / Get number of days in the month 64 int numberOfDays InMonth -get NumberOfDaysInMonth (year, month): 65 /I Pad space before the first day of the month int i-o for (i-0; i Figure 13.9 The program displays a calendar for May 2016. You can also 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started