-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppointment.java
More file actions
131 lines (106 loc) · 4.53 KB
/
Copy pathAppointment.java
File metadata and controls
131 lines (106 loc) · 4.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import java.util.Calendar;
public abstract class Appointment implements Comparable<Appointment>, java.io.Serializable {
private String title;
private String description;
private Calendar appointmentDate;
public Appointment(String title, String description, int day, int month, int year, int hour, int minute, boolean isAM) {
this.description = description;
this.title = title;
appointmentDate = Calendar.getInstance();
appointmentDate.set(year, month, day, hour, minute);
appointmentDate.set(Calendar.HOUR, hour);
appointmentDate.set(Calendar.AM_PM, (isAM)? Calendar.AM : Calendar.PM);
}
public Appointment(String title, String description, int day, int hour, int minute, boolean isAM) {
this.description = description;
this.title = title;
appointmentDate = Calendar.getInstance();
appointmentDate.set(Calendar.DAY_OF_MONTH, day);
appointmentDate.set(Calendar.HOUR, hour);
appointmentDate.set(Calendar.MINUTE, minute);
appointmentDate.set(Calendar.AM_PM, (isAM)? Calendar.AM : Calendar.PM);
}
public Appointment(String title, String description, int hour, int minute, boolean isAM) {
this.description = description;
this.title = title;
appointmentDate = Calendar.getInstance();
appointmentDate.set(Calendar.HOUR, hour);
appointmentDate.set(Calendar.MINUTE, minute);
appointmentDate.set(Calendar.AM_PM, (isAM)? Calendar.AM : Calendar.PM);
}
public abstract boolean occursOn(int year, int month, int day);
@Override
public int compareTo(Appointment other) {
if (other instanceof Daily || this instanceof Daily) {
if(this.isAM() != other.isAM()) return -1*Boolean.compare(this.isAM(),other.isAM());
else if(this.getHour() != other.getHour()) return Integer.compare(this.getHour(), other.getHour());
else if(this.getMinute() != other.getMinute()) return Integer.compare(this.getMinute(), other.getMinute());
else return 0;
} else if (other instanceof Monthly || this instanceof Monthly) {
if(this.getDay() != other.getDay()) return Integer.compare(this.getDay(), other.getDay());
else if(this.isAM() != other.isAM()) return Boolean.compare(this.isAM(), other.isAM());
else if(this.getHour() != other.getHour()) return Integer.compare(this.getHour(), other.getHour());
else if(this.getMinute() != other.getMinute()) return Integer.compare(this.getMinute(), other.getMinute());
else return 0;
} else if (other instanceof Onetime || this instanceof Onetime) {
if (this.getYear() != other.getYear()) Integer.compare(this.getYear(), other.getYear());
else if(this.getMonth() != other.getMonth()) return Integer.compare(this.getMonth(), other.getMonth());
else if(this.isAM() != other.isAM()) return Boolean.compare(this.isAM(), other.isAM());
else if(this.getDay() != other.getDay()) return Integer.compare(this.getDay(), other.getDay());
else if(this.getHour() != other.getHour()) return Integer.compare(this.getHour(), other.getHour());
else if(this.getMinute() != other.getMinute()) return Integer.compare(this.getMinute(),other.getMinute());
else return 0;
}
return -5;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
public Calendar getAppointmentDate() {
return appointmentDate;
}
public int getYear() {
return appointmentDate.get(Calendar.YEAR);
}
public int getMonth() {
return appointmentDate.get(Calendar.MONTH);
}
public int getDay() {
return appointmentDate.get(Calendar.DAY_OF_MONTH);
}
public boolean isAM() {
return appointmentDate.get(Calendar.AM_PM) == Calendar.AM;
}
public int getHour() {
return appointmentDate.get(Calendar.HOUR);
}
public int getMinute() {
return appointmentDate.get(Calendar.MINUTE);
}
public void setTitle(String newTitle) {
title = newTitle;
}
public void setDescription(String newDescription) {
description = newDescription;
}
public void displayAppointment() {
System.out.format("%5tl:%tM %tp%n", appointmentDate, appointmentDate, appointmentDate);
System.out.printf(" %s%n", title);
System.out.printf(" %s%n", description);
}
@Override
public String toString() {
String s1 = String.format("%5tl:%tM %tp%n", appointmentDate, appointmentDate, appointmentDate);
String s2 = String.format(" %s%n", title);
String s3 = String.format(" %s%n", description);
return s1 + s2 + s3;
}
public static void main (String... args) {
Appointment myApp = new Onetime("title", "description", 1, 1, 2017, 8, 0, true);
System.out.println(myApp);
}
//TODO: Add setters for the year, month, day, hour, minute, AM/PM
}