I am having a problem. I am told to make a calendar for any year past 1900. I have everything done except one part. The first and last day of the month. It starts on Sunday each month, and ends on Tuesday. My question is, how do I change it so it doesn't also start and end on the same day each month. Any help is appreciated, thanks.
public class Calendar
{
//main method
public static void main (String[] args)
{
//method
methodCalander ();
} //end of main method
//define methodCalander
public static void methodCalander ()
{
//declaring and assigning variables
int year, year2, day1, daynum, i, date = 1, lastDay, leapyear, dayStart, number = 0;
int start, end = 1, next;
int count = 0, count1 = 0, count2 = 0;
//boolean leap = false;
//asks user to enter year
System.out.println ("Enter a year from 1900 (Enter 0 to terminate)");
year = In.getInt ();
//this is the error message that is shown if the user enters a year less than 1900
if (year < 1900)
System.out.println ("Please enter a year greater or equal to 1900");
//while loop for the month, this makes it so there are 12 months instead of only 1
while (count2 < 12)
{
//makes an empty line for more space
System.out.println ();
//finds out if the month is January
if (count2 == 0)
{
//displays january above the month
System.out.println ("January");
}
//finds out if the month is February
if (count2 == 1)
{
//displays February above the month
System.out.println ("February");
}
//finds out if the month is March
else if (count2 == 2)
{
//displays March above the month
System.out.println ("March");
}
//finds out if the month is April
else if (count2 == 3)
{
//displays April above the month
System.out.println ("April");
}
//finds out if the month is May
else if (count2 == 4)
{
//displays May above the month
System.out.println ("May");
}
//finds out if the month is June
else if (count2 == 5)
{
//displays June above the month
System.out.println ("June");
}
//finds out if the month is July
else if (count2 == 6)
{
//displays July above the month
System.out.println ("July");
}
//finds out if the month is August
else if (count2 == 7)
{
//displays August above the month
System.out.println ("August");
}
//finds out if the month is September
else if (count2 == 8)
{
//displays September above the month
System.out.println ("September");
}
//finds out if the month is October
else if (count2 == 9)
{
//displays October above the month
System.out.println ("October");
}
//finds out if the month is November
else if (count2 == 10)
{
//displays November above the month
System.out.println ("November");
}
else if
//finds out if the month is december
(count2 == 11)
{
//displays December above the month
System.out.println ("December");
}
//days of the week output
System.out.println ("nn S M T W T F S");
//this program subtracts the year entered by the user from 1900
year2 = year - 1900;
/*this equation finds out how many days there are after the year 1900
lets say there are 1000 days after the year 1900, then the program will do 1000 % 7
to find out which day the year starts on*/
day1 = year2 * 365;
//for statement to determine how many days are in the month
for (count = 1 ; count <= 31 ; count++)
{
//switch statement to determine what day of the month it starts on
switch (count2)
{
//determines what day January starts on
case 0:
dayStart = 2;
break;
//determines what day February starts on
case 1:
dayStart = 5;
break;
//determines what day March starts on
case 2:
dayStart = 5;
break;
//determines what day April starts on
case 3:
dayStart = 1;
break;
//determines what day May starts on
case 4:
dayStart = 3;
break;
//determines what day June starts on
case 5:
dayStart = 6;
break;
//determines what day July starts on
case 6:
dayStart = 1;
break;
//determines what day August starts on
case 7:
dayStart = 4;
break;
//determines what day September starts on
case 8:
dayStart = 7;
break;
//determines what day October starts on
case 9:
dayStart = 2;
break;
//determines what day November starts on
case 10:
dayStart = 5;
break;
//determines what day December starts on
case 11:
dayStart = 7;
break;
}
//this if statement is if the month starts on a Monday
if (day1 % 7 == 1)
{
for (start = 1 ; start <= end ; start++)
{
//if statement to determine where it starts
if (start % 6 == 0)
System.out.println ("");
}
}
//This else if statement is if the month starts on a Tuesday
else if (day1 % 7 == 2)
for (start = 1 ; start <= end ; start++)
{
//if statement to determine where it starts
if (start % 6 == 0)
System.out.print ("");
}
//if statement to determine if the month starts on Wednesday
if (day1 % 7 == 3)
{
{
for (start = 1 ; start <= end ; start++)
{
//if statement to determine where it starts
if (start % 6 == 0)
System.out.print ("");
}
}
}
//this else if statement is if the year starts on a Thursday
else if (day1 % 7 == 0)
{
{
for (start = 1 ; start <= end ; start++)
//if statement to determine where it starts
if (start % 6 == 0)
System.out.print ("");
;
}
}
//this else if statement is if the year starts on a Friday
else if (day1 % 7 == 5)
{
for (start = 1 ; start <= end ; start++)
//if statement to determine where it starts
if (start % 6 == 0)
System.out.print ("");
}
//this else if statement is if the month starts on a Saturday
else if (day1 % 7 == 6)
{
for (start = 1 ; start <= end ; start++)
{
//if statement to determine where it starts
if (start % 6 == 0)
System.out.print ("");
}
}
//this else if statement is if the month starts on a Sunday
else if (day1 % 7 == 0)
{
for (start = 1 ; start <= end ; start++)
{
//if statement to determine where it starts
if (start % 6 == 0)
System.out.println ("");
//this makes the count skip a line
if (date % 7 == 7 - count)
{
System.out.println ();
}
}
}
//displays how many spaces out it will be
Out.print (count, 3);
//makes it so the month doesn't repeat
//this organizes the numbers in the calander
if (count % 7 == 0)
//spacing
System.out.println ();
}
count2++;
//spacing
System.out.println ();
}
}
}
Aucun commentaire:
Enregistrer un commentaire