 # Question & Answer: In this lab you are to write a Java program to prompt the user for an integer indicating a year…..

Overview:

In this lab you are to write a Java program to prompt the user for an integer indicating a year

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: In this lab you are to write a Java program to prompt the user for an integer indicating a year…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS \$13/PAGE

and then print the calendar for that year.

Objective:

This lab’s objective is to exercise you with the use of Java’s control statements. You are

required to use exactly one while statement, one for statement and one switch statement.

You will also practice on how to use some basic input methods of the Scanner class and some

formatting techniques of method printf().

Activities:

1. The JulianDate class is used to determine the day of the week for the 1st day

of January.

JulianDate JD = new JulianDate();

int date = JD.toJulian(yr,1,1);

int dayOfWeek = (date+1)%7; // 0 means Sunday, 1 means Monday, etc.

2. Notes:

1. No arrays are allowed in this lab.

2. Your output should be closely similar to the output of the instructor’s sample program.

3. To determine whether a year is a leap year or not:

a. If the year is a century year, the year must be divisible by 400.

b. If the year is not a century year, the year only needs to be divisible by 4.

Question is incomplete without julian class and proper output format

Below Code can Print the calendar of a year given Julian Class is defined

import java.util.Scanner;
public class HelloWorld{

public static void main(String []args){
int leap_year=0,i;
JulianDate JD = new JulianDate();

Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
//System.out.print(year);
if((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
leap_year=1;
else
leap_year=0;

int month=1,days;
while(month<=12)
{
if(month==1|| month==3||month==5||month==7||month==8||month==10||month==12)
days=31;
else if(month==4||month==6||month==9||month==11)
days=30;
else
{
if(leap_year==1)
days=29;
else
days=28;
}
for(i=1;i<=days;i++)
{
int current_date=JD.toJulian(year,month,i);
int day_of_week=(current_date+1)%7;

switch(day_of_week)
{
case 0:
System.out.print(” Day=Sunday Date=”+current_date+” Month=”+get_month_name(month)+” Year=”+year);
break;

case 1:
System.out.print(” Day=Monday Date=”+current_date+” Month=”+get_month_name(month)+” Year=”+year);
break;
case 2:
System.out.print(” Day=Tuesday Date=”+current_date+” Month=”+get_month_name(month)+” Year=”+year);
break;

case 3:
System.out.print(” Day=Wednesday Date=”+current_date+” Month=”+get_month_name(month)+” Year=”+year);
break;

case 4:
System.out.print(” Day=Thursday Date=”+current_date+” Month=”+get_month_name(month)+” Year=”+year);
break;

case 5:
System.out.print(” Day=Friday Date=”+current_date+” Month=”+get_month_name(month)+” Year=”+year);
break;

case 6:
System.out.print(” Day=Saturday Date=”+current_date+” Month=”+get_month_name(month)+” Year=”+year);
break;

default:
break;
}
}

}
}
public static String get_month_name(int number)
{
if(number==1)
return “January”;
else if(number==2)
return “February”;
else if(number==3)
return “March”;
else if(number==4)
return “April”;
else if(number==5)
return “May”;
else if(number==6)
return “June”;
else if(number==7)
return “July”;
else if(number==8)
return “August”;
else if(number==9)
return “September”;
else if(number==10)
return “October”;
else if(number==11)
return “November”;
else if(number==12)
return “December”;
}
}