JAVA PROGRAMMING Introduction to Programming Using Java Write a program that pro
ID: 3678371 • Letter: J
Question
JAVA PROGRAMMING
Introduction to Programming Using Java
Write a program that prompts the user to enter a month (1-12) and a year (e.g., 2012), and then displays a calendar for that month and year as illustrated below:
Your program must use the following methods:
Method Description
void printMonthCalendar( int m, int y ) Displays a calendar like the one above for a specified month and year.
void printMonthHeader( int m, int y ) Displays the header information ( month, year, line separator, 3- character day names) for a calendar.
void printMonthBody( int m, int y ) Displays the days in the calendar associated with the corresponding days of the week.
String getMonthName( int m ) Returns the name of the month for a specified month number (e.g., returns March for m=3).
int getStartDay( int m, int d, int y ) Returns the day of week number (1=Monday,…, 7= Sunday) for the specified month, day, and year. Note this only works for the 1st day of the month.
int getNumDaysInMonth( int m, int y) Returns the number of days in a specified month and year. Leap years are accounted for.
boolean isLeapYear( int y ) Returns true if the specified year is a leap year, and returns false otherwise.
. You must write the code for the remaining methods. Be sure to clearly document your code and your methods.
2. Write a program that prompts the user to specify a year (e.g., 2012) and then displays a calendar for each month in that year. You must reuse the methods from part one
Explanation / Answer
Java: Printing the Calendar Month / Year
This demo program prints the calendar month / year
The month and year are given by user as two integer values.
For example,
for July 2010, they would enter
7 2007
ILLUSTARTION OF THE PROGRAM IS AS UNDER :
The output will be :
Program for Displaying Calendar for Each Month of Given Year/Day :
a program that prompts the user to enter the year and first day of the year and displays the calendar table for that year on the console. For example, if the user entered the year 2005, and 6 for Saturday, Juanuary,1, 2005, the program should then display the calendar for each month of the year.
import java.util.Scanner;
public class DisplayCalendar {
}
Ouput will be :
___________________________________________
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
February 2005
____________________________________________
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
Here is the gist of the above written code :
The first row of dates is displayed way off center to the right.
So, I have Sun Mon Tue Wed......
and then say,
a one was supposed to be under the Sun -- instead its way off to the right of the table.
/*
} // end of class
002 public static void main(String[] args) {
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.