forked from ghostmkg/programming-language
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.java
More file actions
Latest commit
60 lines (45 loc) · 1.49 KB
/
Copy pathDate.java
File metadata and controls
60 lines (45 loc) · 1.49 KB
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
packageCMS;
publicclassDate {
privateintday ;
privateintmonth ;
privateintyear ;
privatestaticfinalint[] daysPerMonth = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
publicDate(intday, intmonth, intyear)
{
if (day <= 0 || (day > daysPerMonth[month] && !(month == 2 && day == 29)))
thrownewIllegalArgumentException("day (" + day + ") out-of-range for the specified month and year");
if (month <= 0 && month >= 12)
thrownewIllegalArgumentException("month (" + month + ") must be 1-12");
if (month == 2 && day == 29 && !(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)))
thrownewIllegalArgumentException("day (" + day + ") out-of range for the specified month and year");
this.day = day;
this.month = month;
this.year = year;
}
publicintgetDay() {
returnday;
}
publicvoidsetDay(intday) {
this.day = day;
}
publicintgetMonth() {
returnmonth;
}
publicvoidsetMonth(intmonth) {
this.month = month;
}
publicintgetYear() {
returnyear;
}
publicvoidsetYear(intyear) {
this.year = year;
}
// public void Display_date()
// {
// System.out.println(day + " / " + month + " / " + year );
// }
publicStringtoString()
{
returnday + " / " + month + " / " + year;
}
}