forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.java
More file actions
91 lines (79 loc) · 1.41 KB
/
Copy pathDate.java
File metadata and controls
91 lines (79 loc) · 1.41 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Represents a date.
*/
public class Date {
private int year;
private int month;
private int day;
/**
* Construct a Date object with default values.
*/
public Date() {
this.year = 2016;
this.month = 1;
this.day = 1;
}
/**
* Construct a Date object with given values.
*/
public Date(int year, int month, int day) {
this.year = year;
this.month = month;
this.day = day;
}
/**
* Returns a String representation of the date.
*/
public String toString() {
return String.format("%02d/%02d/%d",
this.month, this.day, this.year);
}
/**
* Tests whether two dates are equivalent.
*/
public boolean equals(Date that) {
return this.year == that.year
&& this.month == that.month
&& this.day == that.day;
}
/**
* Accessor of the year variable.
*/
public int getYear() {
return this.year;
}
/**
* Accessor of the month variable.
*/
public int getMonth() {
return this.month;
}
/**
* Accessor of the day variable.
*/
public int getDay() {
return this.day;
}
/**
* Mutator of the year variable.
*/
public void setYear(int year) {
this.year = year;
}
/**
* Mutator of the month variable.
*/
public void setMonth(int month) {
this.month = month;
}
/**
* Mutator of the day variable.
*/
public void setDay(int day) {
this.day = day;
}
public static void main(String[] args) {
Date birthday = new Date(1996, 4, 19);
System.out.println(birthday);
}
}