forked from ghostmkg/programming-language
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDate.java
60 lines (45 loc) · 1.49 KB
/
Date.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
package CMS;
public class Date {
private int day ;
private int month ;
private int year ;
private static final int[] daysPerMonth = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
public Date(int day, int month, int year)
{
if (day <= 0 || (day > daysPerMonth[month] && !(month == 2 && day == 29)))
throw new IllegalArgumentException("day (" + day + ") out-of-range for the specified month and year");
if (month <= 0 && month >= 12)
throw new IllegalArgumentException("month (" + month + ") must be 1-12");
if (month == 2 && day == 29 && !(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)))
throw new IllegalArgumentException("day (" + day + ") out-of range for the specified month and year");
this.day = day;
this.month = month;
this.year = year;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
// public void Display_date()
// {
// System.out.println(day + " / " + month + " / " + year );
// }
public String toString()
{
return day + " / " + month + " / " + year;
}
}