-
Notifications
You must be signed in to change notification settings - Fork 0
/
Date.java
64 lines (53 loc) · 1.19 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
61
62
63
64
package lab2try1pr;
public class Date{
private Integer dd, mm, yy;
private void checkAndCorrect(){
if(dd > 31)
dd = 31;
if(mm > 12)
mm = 12;
if(dd <= 0)
dd = 1;
if(mm <= 0)
mm = 1;
}
Date(Integer idd, Integer imm, Integer iyy){
dd = idd;
mm = imm;
yy = iyy;
checkAndCorrect();
}
Date(String date){
dd = Integer.parseUnsignedInt(date.substring(0, 2));
mm = Integer.parseUnsignedInt(date.substring(3, 5));
yy = Integer.parseUnsignedInt(date.substring(6));
checkAndCorrect();
}
Date(Date iDate){
dd = iDate.dd;
mm = iDate.mm;
yy = iDate.yy;
}
Date(){
dd = 1;
mm = 1;
yy = 2000;
}
public Integer getDay(){
return dd;
}
public Integer getMonth(){
return mm;
}
public Integer getYear(){
return yy;
}
public void setDate(Date mdate){
dd = mdate.dd;
mm = mdate.mm;
yy = mdate.yy;
}
public String toString(){
return (dd.toString() + "/" + mm.toString() + "/" + yy.toString());
}
}