Ok, I am working on a program that lets a user enter a year which they want a calender for. The program figures out if the year is a leap year (completed), what day January 1st falls on so that the calender has a starting point (completed, see new code below), and it also assigns each month its number of days (completed).
(see images at the bottom for the code completed thus far. Arrows indicate println's I am using for testing purposes....disregard those...and some code I have changed from the time I scanned the images....which was days ago.)
So the question is: How would I use System.out.print/System.out.println's to print out the calender as shown:
January
S M T W T F S
---------------
(numbers)
WITH PROPER FOMATTING SO THAT THE NUMBERS LINE UP WITH THE DAYS!
.
.
.
December
S M T W T F S
---------------
(numbers)
DayOfTheWeek code:
public int DayOfTheWeek (int yr)
{
int a, y, m, day;
a = (14 - 1) / 12;
y = yr - a;
m = 1 + (12 * a) - 2;
day = (1 + y + (y/4) - (y/100) + (y/400) + ((31*m)/12)) % 7;
return day; //The return "day" will equal 0 for Sunday, 1 for Monday, etc.
}
Also, I tried getting the System.out.print/println's to print out the calender, but I'm getting nowhere.
The way I did the first day was to use 7 IF's that check to see which day Jan 1 is.
Ex.) 0 = Sunday, 1 = Monday ...etc..
Then, under each if is: System.out.print(" ");
Ex.) If the first day is a tuesday then the System.out.print looks like this:
System.out.print(" (5 blank spaces) " + day);
//day is the value of the for loop, which would be 1 the first time through.
But of course this system of IF's would only execute if the calender is only printing the 1st line. I'm stuck on the rest of the printing.....HELP!
Thanks to all who help :mrgreen: