-
Notifications
You must be signed in to change notification settings - Fork 2
/
Facility.java
175 lines (171 loc) · 5.26 KB
/
Facility.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
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
import java.util.*;
import java.text.*;
import java.time.*;
import java.time.format.*;
/**
* Public class for a Facility
*
*/
public class Facility
{
public int facilityId;
public String facilityName;
public double pricePerHour;
public LocalDate decommissionedUntil;
public boolean available;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
/**
*Constructor method if the user "does not want" to decomission the facility, this constructor is used.
*
*@param facilityId Inputs the Id of the facility
*@param facilityName Inputs the name of the facility
*@param pricePerHour Inputs the price of the facility to book per time slot.
*
*/
public Facility(int facilityId, String facilityName, double pricePerHour)
{
this.facilityId = facilityId;
this.facilityName = facilityName;
this.pricePerHour = pricePerHour;
this.available = true;
}
/**
*Constructor method if the user "wants to" decomission the facility, this constructor is used.
*
*@param facilityId Inputs the Id number of the facility
*@param facilityName Inputs the name of the facility
*@param pricePerHour Inputs the price of the facility to book per a time slot
*@param decommissionedUntil Inputs a date and decommissions the facility until that date.
*
*/
public Facility(int facilityId, String facilityName, double pricePerHour, LocalDate decommissionedUntil)
{
this.facilityId = facilityId;
this.facilityName = facilityName;
this.pricePerHour = pricePerHour;
this.decommissionedUntil = decommissionedUntil;
this.available = getAvailability();
}
//IF USER WANTS IT DECOMISSIONED WHEN CREATING FACILITY BUT DATE IS STRING
/**
*Constructor method if the user wants to decomission the facility and enters date as string
*
*@param facilityId Inputs the Id number of the facility.
*@param facilityName Input of the name of the facility.
*@param pricePerHour Input of the price of the facility to book per time slot.
*@param decommissionedUntilDate decommissionedUntil is the date the facility is decommissioned to.
*
*/
public Facility(int facilityId, String facilityName, double pricePerHour, String decommissionedUntilDate)
{
this.facilityId = facilityId;
this.facilityName = facilityName;
this.pricePerHour = pricePerHour;
LocalDate aDate = LocalDate.parse(decommissionedUntilDate, formatter);
this.decommissionedUntil = aDate;
this.available = getAvailability();
}
/**
*Method to Get Facility ID of facility.
*
*@return facilityId Returns a int of the ID number of the facility.
*
*/
public int getFacilityId()
{
return facilityId;
}
/**
*Method to return the name of a facility.
*
*@return facilityName a String returning the name of a facility.
*
*/
public String getFacilityName()
{
return facilityName;
}
/**
*Method to Price per hour of facility
*
*
*@return pricePerHour Returns a double value of the price per hour of the facility. -
*
*/
public double getPricePerHour()
{
return pricePerHour;
}
/**
*Method to get the decommissioned date for a facility.
*
*@return decommissionedUntil Returns a LocalDate of the date of decomission for a facility
*
*/
public LocalDate getDecommissionedUntil()
{
return decommissionedUntil;
}
/**
*Method to get a String containing all of the facilities information available.
*
*@return-returns String of facility information
*
*/
public String facilityToString()
{
String info = "";
if (decommissionedUntil != null)
{
if (decommissionedUntil.isBefore(LocalDate.now()))
info = facilityId + "," + facilityName + "," + pricePerHour + "," + available;
else
{
String temp = decommissionedUntil.format(formatter);
info = facilityId + "," + facilityName + "," + pricePerHour + "," + temp + "," + available;
}
}
else
info = facilityId + "," + facilityName + "," + pricePerHour + "," + available;
return info;
}
/**
*Method to check if a facility is available or decommissioned.
*
*@return Returning a boolean based on the availability of the facility.
*
*/
public boolean getAvailability()
{
LocalDate decommissioned = decommissionedUntil;
LocalDate today = LocalDate.now();
boolean available = false;
if (today.isAfter(decommissionedUntil))
available = true;
return available;
}
/**
*Set method to assign a decommission date to a facility object, this is an alternative to setting it with a LocalDate
*
*@param aDate String of a date that you want to decommision a facility until.
*
*
*/
public void setDecommissionedUntil(String aDate)//SET WITH A STRING
{
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
this.decommissionedUntil=LocalDate.parse(aDate,formatter);
this.available = getAvailability();
}
/**
*Set method to assign a decommission date to a facility object.
*
*@param aDate This is a date that you want to decommision the facility until.
*
*/
public void setDecommissionedUntil(LocalDate aDate)
{
this.decommissionedUntil = aDate;
this.available = getAvailability();
}
}