-
Notifications
You must be signed in to change notification settings - Fork 0
/
Date.java
96 lines (92 loc) · 2.38 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
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
92
93
94
95
96
public class Date {
int day;
int month;
int year;
public Date(int d, int m, int y){
day = d;
month = m;
year = y;
}
public boolean isEarlier(Date two){
if (year != two.year) return year<two.year;
else{
if (month != two.month) return month<two.month;
else{
if (day != two.day) return day<two.day;
}
}
return true;
}
public String toString(){
String monthString = new String();
switch(month){
case 1:
monthString = "January";
break;
case 2:
monthString = "February";
break;
case 3:
monthString = "March";
break;
case 4:
monthString = "April";
break;
case 5:
monthString = "May";
break;
case 6:
monthString = "June";
break;
case 7:
monthString = "July";
break;
case 8:
monthString = "August";
break;
case 9:
monthString = "September";
break;
case 10:
monthString = "October";
break;
case 11:
monthString = "November";
break;
case 12:
monthString = "December";
break;
default:
monthString = "January";
break;
}
String daySuffix = new String();
switch(day){
case 1:
daySuffix = "st";
break;
case 2:
daySuffix = "nd";
break;
case 3:
daySuffix = "rd";
break;
case 21:
daySuffix = "st";
break;
case 22:
daySuffix = "nd";
break;
case 23:
daySuffix = "rd";
break;
case 31:
daySuffix = "st";
break;
default:
daySuffix = "th";
break;
}
return monthString + " " + day + daySuffix + ", " + year;
}
}