-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVaccineSchedule.java
More file actions
87 lines (79 loc) · 2.92 KB
/
VaccineSchedule.java
File metadata and controls
87 lines (79 loc) · 2.92 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
package csci1011.assign6;
/**CSCI 1010 Assign 6
* @author Benjamin Howard
* Class to handle VaccineAppointment objects and give methods for scheduling Appointments
*/
public class VaccineSchedule {
private int firstHour;
private VaccineAppointment[] allAppointments;
/*Creates a schedule object with slots an hour apart based on the difference between endHour and startHour
To use enter hour in 24 hour format EX: 2:00PM = 14
*/
public VaccineSchedule(int startHour, int endHour)
{
if((startHour >= endHour) || (startHour < 8) || (endHour > 20))
{
System.out.println("Error times are not in correct format");
System.exit(0);
}
this.firstHour = startHour;
this.allAppointments = new VaccineAppointment[endHour - startHour];
this.fillSlots();
}
/*Used to fill appointment slots an hour apart from the start hour to end hour. Converts
24Hr time format to 12 hour format and decides if its AM/PM*/
private void fillSlots()
{ int startHour = this.firstHour;
int amPmHelp = 1;
for(int i = 0; i < allAppointments.length; i++, startHour++)
{
if(startHour < 12)
{
String hr = String.valueOf(startHour) +":00" + " AM";
this.allAppointments[i] = new VaccineAppointment(hr);
}
else if(startHour == 12)
{
String hr = String.valueOf(startHour) +":00" + " PM";
this.allAppointments[i] = new VaccineAppointment(hr);
}
else if (startHour > 12)
{
String hr = String.valueOf(amPmHelp)+":00" + " PM";
this.allAppointments[i] = new VaccineAppointment(hr);
amPmHelp++;
}
}
}
/* Returns the appointment an assigned time slot.
Time slot has to be greater than 0 and less than the maximum number of appointments
*/
public VaccineAppointment getAppointment(int timeSlot)
{
if((timeSlot < 1) || (timeSlot > allAppointments.length))
{
return(null);
}else
{
return(this.allAppointments[timeSlot-1]);
}
}
/* Displays the current availability, if an appointment has already been
taken for the given timeslot it will return "Not Available"
*/
public void displayAvailability()
{
for(int i = 0, index = 1; i < this.allAppointments.length; i++, index++ )
{
VaccineAppointment appointment = this.allAppointments[i];
boolean isAvailable = appointment.getIsAvailable();
if(isAvailable == true)
{
System.out.println(index + "." + " " + appointment.getTime() + " - Available");
}else
{
System.out.println(index + ". " + appointment.getTime() + " - Not Available");
}
}
}
}