-
Notifications
You must be signed in to change notification settings - Fork 0
/
calender.java
180 lines (147 loc) · 3.64 KB
/
calender.java
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/****************************************************************
* calender.java
* Author: Himanshu Sharma
* Contact: [email protected]
* Discription : In this program you can check the calender of any year after 1972.
* You have to Enter Year and Month of your choice.
*
/******************************************************************/
import java.util.Scanner;
class calender
{
public String month_name=new String();
/*used to Calcution and display calender*/
public void display()
{
Scanner sc=new Scanner(System.in);
int left,user_year,start_year,day=1,r=0,leap_y=0,i=0,month,last_day,first_day;
start_year=1973;
System.out.println(" *Instruction :- This program will give you calender of any year after 1972");
//enter year to check calender
System.out.println("\nEnter year: ");
user_year=sc.nextInt();
if(start_year>user_year)
{
left=start_year-user_year;
}
else
{
left=user_year-start_year;
}
//counting number of leap year
for(i=start_year;i<user_year;i++)
{
if(i%4==0)
{ if(user_year==1000 || user_year==2000 || user_year==3000 || user_year==4000 || user_year==5000 )
{
if(user_year%4==0 && user_year%400==0)
leap_y=leap_y+1;
}
else
leap_y=leap_y+1;
}
}
left=left+leap_y;
r=left%7;
r=r+1;
System.out.println("Enter month(1-12): ");
month=sc.nextInt();
if(user_year%4==0)
{ if(user_year==1000 || user_year==2000 || user_year==3000 || user_year==4000 || user_year==5000 )
{ if(user_year%400==0)
{
first_day=29;
last_day=29;
}
else
{
first_day=28;
last_day=28;
}
}
else
{
first_day=29;
last_day=29;
}
}
else
{
first_day=28;
last_day=28;
}
/*used to get the month name*/
switch(month)
{ case 1:
month_name="JANUARY";
last_day=31;
break;
case 2:
r=r+31;r=r%7;month_name="FEBRUARY";
break;
case 3:
r=r+first_day+31;r=r%7;
month_name="MARCH";
last_day=31;
break;
case 4:
r=r+(31*2)+first_day;r=r%7;
month_name="APRIL";
last_day=30;
break;
case 5:r=r+30+first_day+(31*2);r=r%7;month_name="MAY";last_day=31;break;
case 6:r=r+30+first_day+(31*3);r=r%7;month_name="JUNE";last_day=30;break;
case 7:r=r+(30*2)+first_day+(31*3);r=r%7;month_name="JULY";last_day=31;break;
case 8:r=r+(30*2)+first_day+(31*4);r=r%7;month_name="AUGUST";last_day=31;break;
case 9:r=r+(30*2)+first_day+(31*5);r=r%7;month_name="SEPTEMBER";last_day=30;break;
case 10:r=r+(30*3)+first_day+(31*5);r=r%7;month_name="OCTOBER";last_day=31;break;
case 11:r=r+(30*3)+first_day+(31*6);r=r%7;month_name="NOVEMBER";last_day=30;break;
case 12:r=r+(30*4)+first_day+(31*6);r=r%7;month_name="DECEMBER";last_day=31;break;
default:System.out.println("\n\t*******Wrong Input*******");System.exit(0);break;
}
/*printing calender*/
System.out.println("\t\t\t\t"+month_name+" "+user_year+"\n");
if(user_year>3000)
{
r=r-1;
}
print_cal(r,last_day);
}
/*printing dates*/
public void print_cal(int r,int last_day)
{
int i=0,day=1;
System.out.println("\tSun\tMon\tTue\tWed\tThu\tFri\tSat\n\n");
while(i<r)
{
System.out.print("\t*");
i++;
}
for(i=r;i<7;i++)
{
System.out.print("\t"+day);
day++;
}
while(day<=last_day)
{
System.out.println();
for(i=1;i<=7;i++)
{ if(day==last_day+1)
{
break;
}
System.out.print("\t"+day);
day++;
}
}
System.out.println("\n\n\t***********************************************************");
}
}
class main
{
public static void main(String args[])
{
calender obj=new calender();
obj.display();
}
}