code
solution
//output
//copyable code
// Calendarprint.java
import java.util.Scanner;
public class Calendarprint
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
String option;
int year_calendar =0;
int month_calendar;
boolean repeatvalue = true;
while (repeatvalue)
{
do
{
System.out.println("please Enter a valid year_calendar 1800 :");
year_calendar=Integer.parseInt(in.nextLine());
} while(year_calendar <1800);
System.out.println("get month_calendar press m or M");
System.out.println("get calendar enter y or Y");
System.out.println("please Enter your chocie:");
option=in.nextLine();
//check year_calendar
if(option.equals("y")||option.equals("Y"))
{
for (int i1 =1; i1<=12; i1++)
{
displaymonth_calendar(year_calendar, i1);
}
}
//check month_calendar
else if(option.equals("m")||option.equals("M"))
{
do
{
System.out.println("*please Enter the month of the year");
month_calendar=Integer.parseInt(in.nextLine());
}while(month_calendar<=0 || month_calendar>12);
displaymonth_calendar(year_calendar, month_calendar);
}
System.out.println("print the another calender:yes/no");
String answer = in.nextLine();
if (answer.equalsIgnoreCase("no"))
{
System.out.println(" Bye");
//set value
repeatvalue = false;
}
}
}
/**
This method calls displaymonth */
public static void displaymonth_calendar(int year_calendar, int month_calendar)
{
displaycalendarTitle(year_calendar, month_calendar);
displaymonth_calendarBody(year_calendar, month_calendar);
}
public static void displaycalendarTitle(int year_calendar1, int month_calendar)
{
System.out.println(" " + get_month_calendar(month_calendar) + " " + year_calendar1);
System.out.println("----------------------------");
System.out.println(" Sun mon Tue Wed Thu Fri Sat");
}
public static void displaymonth_calendarBody(int year_calendar1, int month_calendar1)
{
int startday = getstartday(year_calendar1, month_calendar1);
print(startday, year_calendar1, month_calendar1);
}
public static void print(int startday, int year_calendar1, int month_calendar1)
{
int startday1 = getstartday(year_calendar1, month_calendar1);
int numberdaysmonth_calendar = getNumbOfDaysmonth_calendar(year_calendar1, month_calendar1);
for (int i = 0; i < startday1; i++){
System.out.print(" ");
}
for(int i=1; i<=numberdaysmonth_calendar; i++)
{
System.out.printf("%4d", i);
if((i+startday1)%7 ==0)
{
System.out.println();
}
}
System.out.println();
}
/**
name of the month_calendar
*/
public static String get_month_calendar(int month_calendar)
{
String nameofmonth_calendar = "";
switch(month_calendar)
{
case 1: nameofmonth_calendar = "January";
break;
case 2: nameofmonth_calendar = "February";
break;
case 3: nameofmonth_calendar = "March";
break;
case 4: nameofmonth_calendar = "April";
break;
case 5: nameofmonth_calendar = "May";
break;
case 6: nameofmonth_calendar = "June";
break;
case 7: nameofmonth_calendar = "July";
break;
case 8: nameofmonth_calendar = "Aubuest";
break;
case 9: nameofmonth_calendar = "September";
break;
case 10: nameofmonth_calendar = "October";
break;
case 11: nameofmonth_calendar = "November";
break;
case 12: nameofmonth_calendar = "December";
break;
}
return nameofmonth_calendar;
}
//returns day
public static int getstartday(int year_calendar1, int month_calendar1)
{
int startday = get_Total_Number_Of_Days(year_calendar1, month_calendar1);
startday= startday+3;
return startday%7;
}
public static int get_Total_Number_Of_Days(int year_calendar1, int month_calendar1)
{
int add = 0;
for(int i=1800; i<=year_calendar1; i++)
{
if(is_Leap_year_calendar(i))
{
add = add+366;
}else{
add = add+365;
}
}
for (int i = 1; i < month_calendar1; i++) {
add = add+getNumbOfDaysmonth_calendar(year_calendar1, i);
}
return add;
}
public static int getNumbOfDaysmonth_calendar(int year_calendar, int month_calendar)
{
int days = 0;
switch(month_calendar)
{
case 1: days = 30;
break;
case 2: if(is_Leap_year_calendar(year_calendar))
{
days = 29;
}
else
{
days = 28;
}
break;
case 3: days = 31;
break;
case 4: days = 30;
break;
case 5: days = 31;
break;
case 6: days = 30;
break;
case 7: days = 31;
break;
case 8: days = 31;
break;
case 9: days = 30;
break;
case 10: days = 31;
break;
case 11: days = 30;
break;
case 12: days = 31;
break;
}
return days;
}
/**
leap year_calendar
*/
public static boolean is_Leap_year_calendar(int year_calendar1)
{
return(year_calendar1 %400==0 || year_calendar1%4==0 && year_calendar1%100!=0);
}
}
Use Java please Creating a calendar for a given year A shell for this assignment has...
Write a C# program that prints a calendar for a given year. Call this program calendar. This program needs to use Switch Case in order to call the methods and format to print each month. The program prompts the user for two inputs: 1) The year for which you are generating the calendar. 2) The day of the week that January first is on, you will use the following notation to set the day of the week: ...
Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs: 1) The year for which you are generating the calendar. 2) The day of the week that January first is on, you will use the following notation to set the day of the week: 0 Sunday 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday Your program should...
please follow format of example output, do in python A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by...
In Python 3 please 3.28 LAB: Leap year A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4...
Please write a C program to implement the calendar of the year (after the year 1900) you specify. For example, when you input 1900, the program print the calendar of year 1900 as the figure (partial) down below. Hint 1: Jan. 1st, 1900 is Monday. Hint 2: You will need to consider the case of Leap Year where there are 29 days in the month of February. In common years there are 28 days in the month of February. For...
Must use a function to compute the day. All cin and cout statements must appear in main(). Has to be in c++. lab 10 Problem write a program that prints the day number of the year, given the date in the form month-day year. For example, if the input is 1-1-2006, the day number is 1; if the input is 12 the day number is 359. The program should check for a leap year. A year is a leap year...
Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java, which will contain code that utilizes your Date.java class. You will submit both files (each with appropriate commenting). A very similar project is described in the Programming Projects section at the end of chapter 8, which you may find helpful as reference. Use (your own) Java class file Date.java, and a companion DateClient.java file to perform the following: Ask user to enter Today’s...
A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4 2) If the year is a century year...
Copy all the classes given in classes Calendar, Day, Month, & Year into BlueJ and then generate their documentation. Examine the documentation to see the logic used in creating each class. (Code given below) import java.util.ArrayList; import java.util.Iterator; class Calendar { private Year year; public Calendar() { year = new Year(); } public void printCalendar() { year.printCalendar(); } } class Year { private ArrayList<Month> months; private int number; public Year() { this(2013); } public Year(int number) { this.number = number;...
//Please help me out with this problem.. This problem has to be done in C++ and has to strictly follow the instructions... I have given the expected output of the problem below. 1) Design a class Date: Provide 3 instance variables (int) to store the month, the day number, and the year Provide the following functions Default constructor -sets date to, 1500 Constructor with parameters - if parameters are not valid, set like default constructor setDate if parameters are not...