0% found this document useful (0 votes)
189 views11 pages

Codes of The Perpetual Calendar

This document contains code for a program that displays a perpetual calendar and indicates whether a given year is a leap year. The program prompts the user to enter a username, password, year, month, and day. It then uses a modified Zeller's congruence formula to calculate the day of the week for the given date and displays the calendar for that month. It also outputs whether the year entered is a leap year or not. The user is given the option to run the program again or terminate it.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views11 pages

Codes of The Perpetual Calendar

This document contains code for a program that displays a perpetual calendar and indicates whether a given year is a leap year. The program prompts the user to enter a username, password, year, month, and day. It then uses a modified Zeller's congruence formula to calculate the day of the week for the given date and displays the calendar for that month. It also outputs whether the year entered is a leap year or not. The user is given the option to run the program again or terminate it.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Codes of the Perpetual Calendar and Leap Year Indicator

import java.io.*; class neutral_creeps {

public static void main(String args[])throws Exception { BufferedReader stoopid=new BufferedReader(new InputStreamReader(System.in)); String username;//the username of the program //default username is CALENDAR String password;//the password of the program //default password of the program is GREGORIAN

//loop here is for repetition of calendar program int loop2 = 0; for (loop2=3;loop2>2;loop2++) {

String again=""; String month=""; int year=0, imonth=0, a=0, loop1, day=0; int newmonth=0;

int form1=0,form2=0,form3=0;

//dispday will determine the days that wil display on the selected day int dispday[]={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}; int count =0;//countlimit=0;

int p=0;//will determine the number of days have to adjust int z=0;

int D=0,C=0;//variables for formula

//loop here is for validation of Username and Password for(loop1=2;loop1>1;loop1++) { System.out.print("\n\nEnter Username: ");username=stoopid.readLine(); username=username.toUpperCase();

System.out.print("\nEnter Password: "); password=stoopid.readLine();password=password.toUpperCase();

if (username.equals("CALENDAR")) { if (password.equals("GREGORIAN")) { System.out.println("\nWELCOME USER"); loop1=0; } else {System.out.print("\n Invalid USERNAME or PASSWORD please try again");} } else {System.out.print("\n Invalid USERNAME or PASSWORD please try again");}

System.out.println ("\nMonth/Day compatiblities\n"); System.out.println ("January - 31 days"); System.out.println ("February - 28 days (29 on leap years)"); System.out.println ("March - 31 days"); System.out.println ("April - 30 days"); System.out.println ("May - 31 days");System.out.println ("June - 30 days");System.out.println ("July - 31 days");System.out.println ("August - 31 days");System.out.println ("September - 30 days"); System.out.println ("October - 31 days");System.out.println ("November - 30 days");System.out.println ("December - 31 days");

// loop here is for validation of day-month selection for(int loop3 = 3;loop3>2;loop3++)

System.out.print ("\n\n\nEnter Year: "); year=Integer.parseInt(stoopid.readLine()); System.out.print ("\nEnter Month (Choose a number from 1-12): "); imonth=Integer.parseInt(stoopid.readLine()); System.out.print ("\nEnter Day: (must be between 1-31): ");day=Integer.parseInt(stoopid.readLine());

if(imonth>0&&imonth<13&&year>0) {

if(imonth==1) {a=31;month="January";newmonth=11; } if(imonth==2)//This if statement will deterine if there are 28 or 29 days //on the month of February

{newmonth=12; if(year%4==0) { a=29;} else { a=28;}

month="February";

if(imonth==3) {a=31;month="March";newmonth=1; } if(imonth==4) {a=30;month="April";newmonth=2; } if(imonth==5) {a=31;month="May";newmonth=3; } if(imonth==6) {a=30;month="June";newmonth=4; } if(imonth==7) {a=31;month="July";newmonth=5; } if(imonth==8) {a=31;month="August";newmonth=6; } if(imonth==9) {a=30;month="September";newmonth=7; } if(imonth==10) {a=31;month="October";newmonth=8;

} if(imonth==11) {a=30;month="November";newmonth=9; } if(imonth==12) {a=31;month="December";newmonth=10; }

if(day<=a) { loop3=0;}

else System.out.println ("\nInvalid Date! please try again");

}else System.out.println ("\nInvalid Date! please try again"); }

D=year%100; C=(year-C)/100; if (imonth>0&&imonth<3)

{D=D-1; }

//formula for a modified Zeller's Rule form1=((13*newmonth-1)-(13*newmonth-1)%5)/5; form2=((D-D%4)/4); form3=((C-C%4)/4); p=(1+form1+D+form2+form3-2*C)%7; int bday=0; bday=(day+form1+D+form2+form3-2*C)%7;

/*Zeller's Rule is a formula *that allows you to calculate a *day of the week for ANY date * * *The original formula is * *F= k + [(13 x m - 1)/5] + D + [D/4] + [C/4] - 2 x C * *Where k is the day of the month. Let's *use January 27, 2004 for example. *For this date, k is 27.

* *m is the month number. Months have a different count system: * *March = 1; April = 2; . . . December = 10; *and January = 11; and February = 12; * *this way they can easily detect wether of not February *has a 29th day or not. * *D is the Decade or the Last two numbers of the year *C is the Century of the 1st two numbers of the year * *while solving., drop all remainders. *and after getting F, divide it by 7 and take the remainder. * *it will represent what day of the week the date will fall * *example 1 - Monday, 2 - Tuesday . . . 6 - Saturday and 7 for Sunday *(if the remainder is Zero or less than Zero, add 7) * */

if(bday<=0)

{bday=bday+7; } String sdae=""; if(bday==7) {sdae="Sunday"; } if(bday==1) {sdae="Monday"; } if(bday==2) {sdae="Tuesday"; } if(bday==3) {sdae="Wednesday"; } if(bday==4) {sdae="Thursday"; } if(bday==5) {sdae="Friday"; } if(bday==6) {sdae="Saturday"; }

if(p<0) {p=p+7; }

System.out.println ("\n\n\t "+month+" "+year); System.out.println ("Su\tM\tT\tW\tTh\tF\tSa\t\n"); for(int x=1;x<=6;x++) { for(int y=0;y<=6;y++) { while(z<p) {System.out.print (" \t"); z++;y++;} System.out.print (dispday[count]+"\t"); count++;

//this is the beginning of the CALENDAR

if(count==a) {y=7;x=7;} }System.out.println (""); }

//This is where the CALENDAR ends

System.out.println ("\nThe date you chose is "+month+" "+day+", "+year); System.out.println ("The day you chose is "+sdae);

if(year%4==0) {System.out.println ("This year is a Leap Year"); }

else {System.out.println ("This year is NOT a Leap Year");}

for(int loop4=3;loop4>2;loop4++) { System.out.print ("\n\nDo you wish to terminate the program ? y/n: "); again=stoopid.readLine();again=again.toUpperCase();

if(again.equals("Y")) { System.out.print ("\nThank you for using my program"); loop2=0;loop4=0; } else if(again.equals("N")) {System.out.println ("\nYou have chosen to run the program again"); loop4=0; } else {System.out.println ("\nIncorrect choice! please try again");}

}}}}

You might also like