-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMyDateClass.java
More file actions
62 lines (50 loc) · 1.39 KB
/
MyDateClass.java
File metadata and controls
62 lines (50 loc) · 1.39 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
61
62
public class MyDate {
private int day;
private int month;
private int year;
public MyDate(int day, int month, int year) {
this.day = day;
this.month = month;
this.year = year;
}
public String toString() {
return this.day + "." + this.month + "." + this.year;
}
public boolean earlier(MyDate compared) {
if (this.year < compared.year) {
return true;
}
if (this.year == compared.year && this.month < compared.month) {
return true;
}
if (this.year == compared.year && this.month == compared.month
&& this.day < compared.day) {
return true;
}
return false;
}
public void advance(){
if(this.day < 30){
this.day++;
}else if(day == 30 && this.month < 12){
this.day = 1;
this.month++;
}else if(this.day == 30 && this.month == 12){
this.day = 1;
this.month = 1;
this.year++;
}
}
public void advance(int numberOfDays){
int i = 0;
while(i < numberOfDays){
this.advance();
i++;
}
}
public MyDate afterNumberOfDays(int days){
MyDate afterDate = new MyDate(this.day, this.month, this.year);
afterDate.advance(days);
return afterDate;
}
}