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

Requirements/PROMPT: /*********************************************** * Your Hea

ID: 3698401 • Letter: R

Question

Requirements/PROMPT:

/***********************************************

* Your Header Goes Here

**********************************************/

import java.util.Scanner;

public class PrintCalendar

{

/*The main method has only one line of code and it calls the process

method

You do not need to change anything in this method*/

public static void main(String[] args)

{

process();

}

/*This method ask the required info and calls the appropriate methods

based on the user's input to either print

the calendar for the month or for the year. You can declare your

Scanner object in this method since it

will only be used here */

public static void process()

{

}

//this method prints the body of the calender for the given month by

calling the the methods printMonthTable and printMonthBody

public static void printMonth(int year, int month)

{

printMonthTitle(year, month);

printMonthBody(year, month);

}

//this method prints the title of the days in each week(sunday Mon Tues

Wed Thur Fir Sat)

/*This method prints the following

month name year

----------------------------

Sun Mon Tue Wed Thu Fri Sat

this method gets the month as an integer and you need to call the

appropriate method to get the name of the month*/

public static void printMonthTitle(int year, int month)

{

}

/*this method calls the method getStartday to find out the first day of

the month(sunday, monday, tuesday, wednesday, thursday or friday

then it calls the method print by passing the startday, year and

month*/

public static void printMonthBody(int year, int month)

{

}

/*This method prints the days in the month, you will need to call the

getNumberOfDaysInMonth method

to get the appropriate number of days and you will also need to print

out the day that Thanksgiving

is on if the month is November (using the thanks method)*/

public static void print(int startDay, int year, int month)

{

}

/*This method finds out the day of thanksgiving

you must use switch statements . Thanksgiving is the last Thursday of

November therefore we need to add a value to 21.

for example if the first of the month is sunday then from sunday to

thurday is 5 days, then we add 5 to 21 and that would be the thanksgiving

day.

The first day of November 2018 is Thursday and so thanksgiving will be

on 1 + 3 * 7 = 22*/

public static int thanks(int startDay)

{

return 0;

***********************************************************************************************************************************************************

SAMPLE OUTPUT:

Problem Write a program that prints the calendar for a given year or a given month. The user will be given the option of printing the calendar for the whole year or just a month. If the calendar for the whole year is being printed then the data for thanksgiving must be specified. You are required to create multiple methods. Also you need to consider if the year is a leap year or not. Sample Output: output.txt Shell: PrintCalendar.java How to proceed to solving this problem 1. You need to find out how many days has passed since Jan 1800 up to the given year. You must check if the year is a leap year or not to know the number of the days in February 2. You need to find out the first day of the month for each given month which is going to be Sunday, Monday, Tuesday, Wednesday, Thursday, Friday or Saturday 3. You need to find out the Thanksgiving Day for the given year 4. Now you are ready to print the calendar. 5. Refer to the provided shell for more details Requirements: 1. Must implement all the provided methods in the shell 2. Your program must work for a leap year as well 3. Your program must output a description indicating what the program does 4. Naming conventions 5. Indentation 6. Proper way of calling methods 7. Use of conditional statements 8. You are allowed to be creative by adding more functionality to your program 9. You can deviate from the provided shell and create your own solution. However you must use ample number of methods.

Explanation / Answer


package Calenders;
import java.time.YearMonth;
import java.util.Scanner;
public class PrintCalendar
{
/*
* The main method has only one line of code and it calls the process
*
* method
*
* You do not need to change anything in this method
*/
public static void main(String[] args)
{
process();
}
/*
* This method ask the required info and calls the appropriate methods
*
* based on the user's input to either print
*
* the calendar for the month or for the year. You can declare your
*
* Scanner object in this method since it
*
* will only be used here
*/
public static void process()
{
Scanner in=new Scanner(System.in);
System.out.println("How many times do you want to try this app?");
int no=in.nextInt(),choice;
for (int i = 0; i < no; i++) {
System.out.println("To print the Calender choose one of the following options...");
System.out.println("1 for Year");
System.out.println("2 for Month");
choice=in.nextInt();
switch(choice)
{
case 1:System.out.println("Enter a valid Year after 1800:");
int yr=in.nextInt();
printMonthsOfYear(yr);
break;
case 2:System.out.println("Enter a valid Year after 1800:");
int yr2=in.nextInt();
System.out.println("Enter the month of the year that you want the calender");
int mnth=in.nextInt();
printMonth(yr2,mnth);
break;
default : System.out.println("Invalid input");
}
}
}
public static boolean isLeapYear(int year)
{
boolean flag = false;
if(year % 400 == 0)
{
flag = true;
}
else if (year % 100 == 0)
{
flag = false;
}
else if(year % 4 == 0)
{
flag = true;
}
else
{
flag = false;
}
return flag;
}
public static void printMonthsOfYear(int year)
{
for (int i = 1; i <= 12; i++) {
printMonthTitle(year, i);
printMonthBody(year, i);
}
if(isLeapYear(year))
System.out.println("**It's a Leap Year");
else
System.out.println("**It's not a Leap Year");
}
// this method prints the body of the calender for the given month by
//calling the
//the methods
//printMonthTable and printMonthBody
public static void printMonth(int year, int month)
{
printMonthTitle(year, month);
printMonthBody(year, month);
if(isLeapYear(year))
System.out.println("**It's a Leap Year");
else
System.out.println("**It's not a Leap Year");
}
// this method prints the title of the days in each week(sunday Mon Tues
//Wed Thur
//Fir Sat)
/*
* This method prints the following
*
* month name year
*
* ----------------------------
*
* Sun Mon Tue Wed Thu Fri Sat
*
* this method gets the month as an integer and you need to call the
*
* appropriate method to get the name of the month
*/
public static void printMonthTitle(int year, int month)
{
String monthName="";
switch(month)
{
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";
break;
default: monthName="Not a Calender Month";
}
System.out.println("----------"+monthName+" "+year+"----------");
}
/*
* this method calls the method getStartday to find out the first day of
*
* the month(sunday, monday, tuesday, wednesday, thursday or friday
*
* then it calls the method print by passing the startday, year and
*
* month
*/
public static void printMonthBody(int year, int month)
{
YearMonth ym = YearMonth.of(year, month);
int firstDayVal = ym.atDay(1).getDayOfWeek().getValue();
print(firstDayVal,year,month);
}
/*
* This method prints the days in the month, you will need to call the
*
* getNumberOfDaysInMonth method
*
* to get the appropriate number of days and you will also need to print
*
* out the day that Thanksgiving
*
* is on if the month is November (using the thanks method)
*/
public static void print(int startDay, int year, int month)
{
YearMonth ym = YearMonth.of(year, month);
int totalDays = ym.lengthOfMonth();
System.out.println("startDay-"+ym.atDay(1).getDayOfWeek().name());
System.out.println(" Sun Mon Tue Wed Thu Fri Sat");
System.out.println();
int modifiedVal=(startDay==7)?1:startDay+1;
int count=1;
for (int j = 1; j < modifiedVal; j++) {
System.out.print(" ");
count++;
}
for (int i = 1; i <=totalDays; i++) {
if(count%7==0)
{
System.out.print(" "+i);
count++;
System.out.println();
continue;
}
System.out.print(" "+i);
count++;
}
System.out.println();
if(month==11)
{
System.out.println("**Thanks giving day is on : "+thanks(startDay));
}
}
/*
* This method finds out the day of thanksgiving
*
* you must use switch statements . Thanksgiving is the last Thursday of
*
* November therefore we need to add a value to 21.
*
* for example if the first of the month is sunday then from sunday to
*
* thurday is 5 days, then we add 5 to 21 and that would be the thanksgiving
*
* day.
*
* The first day of November 2018 is Thursday and so thanksgiving will be
*
* on 1 + 3 * 7 = 22
*/
public static int thanks(int startDay)
{
int add=0;
switch(startDay)
{
case 4:add=1;
break;
case 7:add=5;
break;
case 6:add=6;
break;
case 5:add=7;
break;
case 3:add=2;
break;
case 2:add=3;
break;
case 1:add=4;
break;
}
return add+21;
}
}

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