-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppointmentBook.java
More file actions
230 lines (188 loc) · 7.23 KB
/
Copy pathAppointmentBook.java
File metadata and controls
230 lines (188 loc) · 7.23 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Scanner;
import java.util.Comparator;
import java.util.Collections;
public class AppointmentBook implements java.io.Serializable {
public ArrayList<Appointment> appointments;
public AppointmentBook(Appointment... theAppointments) {
this.appointments = new ArrayList<Appointment>();
for (Appointment a : theAppointments) {
appointments.add(a);
}
}
public AppointmentBook(ArrayList<Appointment> theAppts){
appointments = theAppts;
}
public void displayAppointments() {
for (Appointment a : appointments) {
a.displayAppointment();
}
}
public void writeToFile(){
}
public void add(Appointment a){
appointments.add(a);
}
//TODO: only goes to day before endday. fix this.
public void displayAppointmentsFromTo(int startYear, int endYear, int startDay, int endDay, int startMonth, int endMonth) {
Collections.sort(appointments);
ArrayList<Appointment> apptsLeft = new ArrayList<Appointment>();
ArrayList<GregorianCalendar> appointmentDates = new ArrayList<GregorianCalendar>();
for (Appointment a : appointments) apptsLeft.add(a);
//for (Appointment a : appointments) a.displayAppointment();
System.out.println("Checkpoint 1");
GregorianCalendar startDate = new GregorianCalendar(startYear, startMonth, startDay);
GregorianCalendar endDate = new GregorianCalendar(endYear, endMonth, endDay);
int count = 0;
while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) {
System.out.println("Checkpoint 2");
System.out.println(appointments);
boolean found = false;
for (Appointment a : appointments) {
if (a.occursOn(startDate.get(Calendar.YEAR),
startDate.get(Calendar.MONTH),
startDate.get(Calendar.DAY_OF_MONTH))) {
appointmentDates.add((GregorianCalendar) startDate.clone());
startDate.add(Calendar.DAY_OF_MONTH, 1);
System.out.println(startDate.getTimeInMillis() + "=startdatemillis");
System.out.println(endDate.getTimeInMillis() + "=enddatemillis");
found = true;
// startDate.setTime((new Date(startDate.getTime() + 8640000)));
// System.out.println(startDate.get(Calendar.MONTH) + "-" + startDate.get(Calendar.DAY_OF_MONTH) + "-" + startDate.get(Calendar.YEAR));
break;
}
}
if (!found) {
startDate.add(Calendar.DAY_OF_MONTH, 1);
}
count++;
System.out.println(startDate.getTimeInMillis());
System.out.println("Checkpoint 3");
System.out.println("count " + count);
}
System.out.println("Checkpoint 4");
for (GregorianCalendar g : appointmentDates) {
System.out.println(g.get(Calendar.MONTH) + "-" + g.get(Calendar.DAY_OF_MONTH) + "-" + g.get(Calendar.YEAR));
ArrayList<Appointment> theseAppointments = new ArrayList<Appointment>();
for (Appointment a : appointments) {
if (a.occursOn(g.get(Calendar.YEAR),
g.get(Calendar.MONTH),
g.get(Calendar.DAY_OF_MONTH))) {
theseAppointments.add(a);
}
}
AppointmentBook tempAB = new AppointmentBook(theseAppointments);
tempAB.sortAppointments();
tempAB.displayAppointments();
}
}
public void remove() {
}
public ArrayList<Appointment> findAppointmentsOn(int year, int month, int day) {
ArrayList<Appointment> theseAppointments = new ArrayList<Appointment>();
for (Appointment a : appointments) {
if (a.occursOn(year, month, day)) theseAppointments.add(a);
}
return theseAppointments;
}
public void modify() {
}
public void sortAppointments() {
Collections.sort(appointments);
}
//temp method for debugging
public ArrayList<Appointment> getApptList() {
return appointments;
}
public String toString(int startYear, int endYear, int startDay, int endDay, int startMonth, int endMonth) {
String rs = "";
Collections.sort(appointments);
ArrayList<Appointment> apptsLeft = new ArrayList<Appointment>();
ArrayList<GregorianCalendar> appointmentDates = new ArrayList<GregorianCalendar>();
for (Appointment a : appointments) apptsLeft.add(a);
//for (Appointment a : appointments) a.displayAppointment();
GregorianCalendar startDate = new GregorianCalendar(startYear, startMonth, startDay);
GregorianCalendar endDate = new GregorianCalendar(endYear, endMonth, endDay);
while (startDate.getTimeInMillis() < endDate.getTimeInMillis()) {
System.out.println("Checkpoint 2");
System.out.println(appointments);
boolean found = false;
for (Appointment a : appointments) {
if (a.occursOn(startDate.get(Calendar.YEAR),
startDate.get(Calendar.MONTH),
startDate.get(Calendar.DAY_OF_MONTH))) {
appointmentDates.add((GregorianCalendar) startDate.clone());
startDate.add(Calendar.DAY_OF_MONTH, 1);
System.out.println(startDate.getTimeInMillis() + "=startdatemillis");
System.out.println(endDate.getTimeInMillis() + "=enddatemillis");
found = true;
// startDate.setTime((new Date(startDate.getTime() + 8640000)));
// System.out.println(startDate.get(Calendar.MONTH) + "-" + startDate.get(Calendar.DAY_OF_MONTH) + "-" + startDate.get(Calendar.YEAR));
break;
}
}
if (!found) {
startDate.add(Calendar.DAY_OF_MONTH, 1);
}
//count++;
System.out.println(startDate.getTimeInMillis());
System.out.println("Checkpoint 3");
//System.out.println("count " + count);
}
System.out.println("Checkpoint 4");
for (GregorianCalendar g : appointmentDates) {
rs += String.format(g.get(Calendar.MONTH) + "-" + g.get(Calendar.DAY_OF_MONTH) + "-" + g.get(Calendar.YEAR)+"%n");
ArrayList<Appointment> theseAppointments = new ArrayList<Appointment>();
for (Appointment a : appointments) {
if (a.occursOn(g.get(Calendar.YEAR),
g.get(Calendar.MONTH),
g.get(Calendar.DAY_OF_MONTH))) {
theseAppointments.add(a);
}
}
AppointmentBook tempAB = new AppointmentBook(theseAppointments);
tempAB.sortAppointments();
for (Appointment a : tempAB.getAppointments()) rs += a.toString();
}
return rs;
}
private ArrayList<Appointment> getAppointments() {
return this.appointments;
}
/*
public static void main(String... args) {
AppointmentBook myAppointmentBook = new AppointmentBook();
myAppointmentBook.add(new Onetime(
"Dentist's Appointment, #2",
"Check out potential cavity at dentist's office",
15, 3, 2016, 7, 30, false)
);
myAppointmentBook.add(new Onetime(
"Doctor's Appointment, #3",
"Check out potential tumor at doctor's office",
20, 3, 2016, 7, 30, false)
);
myAppointmentBook.add(new Monthly(
"Have a good first of the month, #2",
"Check out potential tumor at doctor's office",
1, 1, 00, false)
);
myAppointmentBook.add(new Daily(
"Wake Up, #1",
"I have to wake up for the day ahead of me",
7, 30, true)
);
myAppointmentBook.add(new Onetime(
"Mini Golf, #4",
"Check out potential tumor at doctor's office",
20, 4, 2016, 6, 30, false)
);
myAppointmentBook.sortAppointments();
for (Appointment a:myAppointmentBook.getApptList()) a.displayAppointment();
//myAppointmentBook.findAppointmentsOn(2016, 3, 20).get(0).displayAppointment();
//myAppointmentBook.displayAppointmentsFromTo(2016, 2016, 10, 10, 3, 4);
System.out.print(myAppointmentBook.toString(2016, 2016, 10, 10, 3, 4));
}*/
}