Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will write 2 methods besides main(). These 2 methods arecalled from main().

ID: 3616149 • Letter: Y

Question

You will write 2 methods besides main(). These 2 methods arecalled from main(). The method definitions are: public static void main(String args[]){ /*...*/} public static void prtMonthTitle( int month ){ /*...*/} public static int getNumDaysInMonth( int month ){/*...*/ } ----------------------------------------start-upcode---------- public class xxxx { private static final int JAN = 1; //January public static void main( String args[]) { final int FRI = 6; // Friday - 1st day inyear final int DAYS_WK = 7; // 7 days inweek char choice ; // Repeat loop int mon; // Month of year int days = 0; // Number of days in amonth Scanner scan = new Scanner(System.in); // Readinput from keyboard String inputStr = null; // Inputstring do { System.out.print("Enter month in 2010 to displaycalendar (1-12): "); mon = scan.nextInt(); // Input calendarmonth // … prtMonthTitle(mon); for( i = 1 ; i <= mon ; ++i) { days = getNumDaysInMonth(i); // … } System.out.print("Want to display another month(y/n)? "); inputStr = scan.next(); // Read and assign toString choice = inputStr.charAt(0); // Assign tocharacter } //Loop while NOT n or N… }
--------------------------
b) No instance variables are needed. Constant types such as "private static final int JAN = 1;" will increase readability of your code. Produce a calendar month only for valid input. Do not usearrays or any other construct
c) main() handles input month number and program termination.Handle input for an integer and a character Check for a legal input of month range (1-12) using a loop.Output an error message if an out-of-range value is entered and prompt foranother integer to be input. Do not display a calendar month for invalid input. Theprogram will only accept input between 1-12 for a month. Call prtMonthTitle() upon legal input for month number. Do notdisplay a calendar for a month in an incorrect range. Call (invoke) themethod " prtMonthTitle(mon);" to print the month and days of thecalendar heading. Call "days = getNumDaysInMonth(i);" to calculate the number ofdays that have passed to start the 1st day in the month. A loop to print the loop counter is efficient“System.out.printf(“%7d”, i);” Notice a newline is printed after Saturday (7th day) andbefore Sunday (1st day). The 1st day of the month (Day “1”) will have the“1” positioned under the correct day of the week heading. e.g. 1st day of October is onFriday. A loop printing a chunk of blank spaces, “ “, for eachday (5 chunks of blanks before printing “1” under Friday position. The first day of the month occurs on these following days ofthe week: January: Friday February: Monday March: Monday April: Thursday May: Saturday June: Tuesday July: Thursday August: Sunday September: Wednesday October: Friday November: Monday December: Wednesday NOTE: Do NOT hardcode this into your program (what if theprogram is modified to allow calendar year input? Calculate the OFFSET (addition ofdays from January 1st to current month. See HINTS section below.
d) In the method definition of prtMonthTitle(int month) youwill print the name of the month passed as a parameter along with the days of theweek.
e) In the method definition of getNumDaysInMonth(int month),you will calculate the number of days in the month passed as a parameter. In 2010, February, the 2nd month, has 28 days in themonth. These months have 30 days: April, June, September, andNovember (4, 6, 9, 11). These months have 31 days: January, March, May, July, August, October, December (1, 3, 5,7, , 10, 12)
f) Allow your program to repeat this calculation as often asthe user wishes until the user types in a single character of an 'n' or 'N'. NOTE:Program ONLY stops on 'n' or 'N'.

-----------------------output------------------------
Enter month in 2010 to display calendar (1-12): 1 *******************JANUARY******************* SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Want to display another month (y/n)? y Enter month in 2010 to display calendar (1-12): 7 ********************JULY********************* SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Want to display another month (y/n)? X Enter month in 2010 to display calendar (1-12): 13 ERROR - Enter month in range of (1-12)! Enter month in 2010 to display calendar (1-12): 2 *******************FEBRUARY****************** SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Want to display another month (y/n)? N You will write 2 methods besides main(). These 2 methods arecalled from main(). The method definitions are: public static void main(String args[]){ /*...*/} public static void prtMonthTitle( int month ){ /*...*/} public static int getNumDaysInMonth( int month ){/*...*/ } ----------------------------------------start-upcode---------- public class xxxx { private static final int JAN = 1; //January public static void main( String args[]) { final int FRI = 6; // Friday - 1st day inyear final int DAYS_WK = 7; // 7 days inweek char choice ; // Repeat loop int mon; // Month of year int days = 0; // Number of days in amonth Scanner scan = new Scanner(System.in); // Readinput from keyboard String inputStr = null; // Inputstring do { System.out.print("Enter month in 2010 to displaycalendar (1-12): "); mon = scan.nextInt(); // Input calendarmonth // … prtMonthTitle(mon); for( i = 1 ; i <= mon ; ++i) { days = getNumDaysInMonth(i); // … } System.out.print("Want to display another month(y/n)? "); inputStr = scan.next(); // Read and assign toString choice = inputStr.charAt(0); // Assign tocharacter } //Loop while NOT n or N… }
--------------------------
b) No instance variables are needed. Constant types such as "private static final int JAN = 1;" will increase readability of your code. Produce a calendar month only for valid input. Do not usearrays or any other construct
c) main() handles input month number and program termination.Handle input for an integer and a character Check for a legal input of month range (1-12) using a loop.Output an error message if an out-of-range value is entered and prompt foranother integer to be input. Do not display a calendar month for invalid input. Theprogram will only accept input between 1-12 for a month. Call prtMonthTitle() upon legal input for month number. Do notdisplay a calendar for a month in an incorrect range. Call (invoke) themethod " prtMonthTitle(mon);" to print the month and days of thecalendar heading. Call "days = getNumDaysInMonth(i);" to calculate the number ofdays that have passed to start the 1st day in the month. A loop to print the loop counter is efficient“System.out.printf(“%7d”, i);” Notice a newline is printed after Saturday (7th day) andbefore Sunday (1st day). The 1st day of the month (Day “1”) will have the“1” positioned under the correct day of the week heading. e.g. 1st day of October is onFriday. A loop printing a chunk of blank spaces, “ “, for eachday (5 chunks of blanks before printing “1” under Friday position. The first day of the month occurs on these following days ofthe week: January: Friday February: Monday March: Monday April: Thursday May: Saturday June: Tuesday July: Thursday August: Sunday September: Wednesday October: Friday November: Monday December: Wednesday NOTE: Do NOT hardcode this into your program (what if theprogram is modified to allow calendar year input? Calculate the OFFSET (addition ofdays from January 1st to current month. See HINTS section below.
d) In the method definition of prtMonthTitle(int month) youwill print the name of the month passed as a parameter along with the days of theweek.
e) In the method definition of getNumDaysInMonth(int month),you will calculate the number of days in the month passed as a parameter. In 2010, February, the 2nd month, has 28 days in themonth. These months have 30 days: April, June, September, andNovember (4, 6, 9, 11). These months have 31 days: January, March, May, July, August, October, December (1, 3, 5,7, , 10, 12)
f) Allow your program to repeat this calculation as often asthe user wishes until the user types in a single character of an 'n' or 'N'. NOTE:Program ONLY stops on 'n' or 'N'.

-----------------------output------------------------
Enter month in 2010 to display calendar (1-12): 1 *******************JANUARY******************* SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Want to display another month (y/n)? y Enter month in 2010 to display calendar (1-12): 7 ********************JULY********************* SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Want to display another month (y/n)? X Enter month in 2010 to display calendar (1-12): 13 ERROR - Enter month in range of (1-12)! Enter month in 2010 to display calendar (1-12): 2 *******************FEBRUARY****************** SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Want to display another month (y/n)? N Enter month in 2010 to display calendar (1-12): 1 *******************JANUARY******************* SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Want to display another month (y/n)? y Enter month in 2010 to display calendar (1-12): 7 ********************JULY********************* SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Want to display another month (y/n)? X Enter month in 2010 to display calendar (1-12): 13 ERROR - Enter month in range of (1-12)! Enter month in 2010 to display calendar (1-12): 2 *******************FEBRUARY****************** SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Want to display another month (y/n)? N

Explanation / Answer

please rate - thanks import java.util.*; public class calendar2010 {public static void main(String[] args) {int month=0,days,blanks,i; final int DAYS_WK = 7; // 7 days in week String choice; Scanner in =new Scanner(System.in); do { while(month12)    { System.out.println("Enter Month (1-12): ");      month=in.nextInt();       } prtMonthTitle(month-1); days = getNumDaysInMonth(month-1); GregorianCalendar cal = new GregorianCalendar(2010,month-1,1); blanks=cal.get(Calendar.DAY_OF_WEEK)-1; for(i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote