-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.java
More file actions
75 lines (60 loc) · 1.53 KB
/
Copy pathDate.java
File metadata and controls
75 lines (60 loc) · 1.53 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
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.io.Serializable;
import java.util.Objects;
public class Date implements Serializable, Comparable<Date> {
private int day;
private int month;
private int year;
/*default constructor*/
public Date(){
this.day = 0;
this.month = 0;
this.year = 0;
}
public Date(int day, int month, int year){
this.day = day;
this.month = month;
this.year = year;
}
public int getDay(){
return this.day;
}
public void setDay(int day){
this.day = day;
}
public int getMonth(){
return this.month;
}
public void setMonth(int month){
this.month = month;
}
public int getYear(){
return this.year;
}
public void setYear(int year){
this.year = year;
}
public int getDays(){
return this.year*365 + this.month*30 +this.day;
}
@Override
public String toString(){
return this.getDay()+"/"+this.getMonth()+"/"+this.getYear();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Date)) return false;
Date date = (Date) o;
return getDay() == date.getDay() &&
getMonth() == date.getMonth() &&
getYear() == date.getYear();
}
@Override
public int hashCode() {
return Objects.hash(getDay(), getMonth(), getYear());
}
@Override
public int compareTo(Date date) {
return this.getDays() - date.getDays();
}
}