Repository navigation
Expand file tree
/
Copy pathProperty.java
More file actions
262 lines (245 loc) · 8.83 KB
/
Copy pathProperty.java
File metadata and controls
262 lines (245 loc) · 8.83 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Scanner;
// property model class
public class Property {
private static int lastID; // holds last property ID, used to set new propertyID to lastID + 1
private int propertyID; // property unique identifier
private String titileName; // property title
private double price; // rent price
private int size; // property size
private String[] propertyPicturePath; //property picture paths
private Address propertyAddress;
private int bedRoomsNum; // number of bedrooms
private int bathRoomsNum;
private String propertyType;
private String furnishing;
private String propertyActivationStatus;
private String propertyApprovalStatus;
private String[] availableFacilities; // property facilities
private String[] availableFeatures;
private String description;
private String tenantName;
private String agentName;
// main constructor, used to create properties that are read from files
public Property(int propertyID,String titileName,double price,int size, String[] propertyPicturePath,Address propertyAddress,
int bedRoomsNum, int bathRoomsNum, String propertyType, String furnishing, String propertyActivationStatus,
String propertyApprovalStatus, String[] availableFacilities, String[] availableFeatures,
String description, String tenantName, String agentName) {
this.propertyID = propertyID;
this.titileName = titileName;
this.size = size;
this.price = price;
this.propertyPicturePath = propertyPicturePath;
this.propertyAddress = propertyAddress;
this.bathRoomsNum= bathRoomsNum;
this.bedRoomsNum = bedRoomsNum;
this.propertyType = propertyType;
this.furnishing = furnishing;
this.propertyActivationStatus = propertyActivationStatus;
this.propertyApprovalStatus = propertyApprovalStatus;
this.availableFacilities = availableFacilities;
this.availableFeatures = availableFeatures;
this.description = description;
this.tenantName = tenantName;
this.agentName = agentName;
}
// constructor to write property to files, will set propertyID according to lastID
public Property(String titileName,double price,int size, Address propertyAddress,
int bedRoomsNum, int bathRoomsNum, String propertyType, String furnishing, String propertyActivationStatus,
String propertyApprovalStatus, String[] availableFacilities, String[] availableFeatures,
String description, String tenantName, String agentName) {
this.titileName = titileName;
this.size = size;
this.price = price;
this.propertyAddress = propertyAddress;
this.bathRoomsNum= bathRoomsNum;
this.bedRoomsNum = bedRoomsNum;
this.propertyType = propertyType;
this.furnishing = furnishing;
this.propertyActivationStatus = propertyActivationStatus;
this.propertyApprovalStatus = propertyApprovalStatus;
this.availableFacilities = availableFacilities;
this.availableFeatures = availableFeatures;
this.description = description;
this.tenantName = tenantName;
this.agentName = agentName;
try {
lastID = readPropertyLastID();
this.propertyID = ++lastID;
sendPropertyLastID(lastID);
this.savePropertyFile();
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
// read lastID file, if not found(first property to create) return 0
private int readPropertyLastID() throws FileNotFoundException {
File lastIDFile = new File("System/Property Manager/PropertyLastID.txt");
if(lastIDFile.exists()) {
Scanner lastIDScanner = new Scanner(lastIDFile);
int lastIDread =lastIDScanner.nextInt();
lastIDScanner.close();
return lastIDread;
}
else
return 0;
}
private void sendPropertyLastID(int lastID){ // set the lastID file to the new one.
try{
FileWriter LastIDFile = new FileWriter("System/Property Manager/PropertyLastID.txt");
PrintWriter outputNames = new PrintWriter(LastIDFile);
outputNames.println(lastID);
outputNames.close();
}
catch(IOException ex){
System.out.println(ex.getMessage());
}
}
// save property to files
public final void savePropertyFile() throws IOException{
new File("System\\Property Manager\\" + agentName + "\\Properties\\"+ propertyID + "\\propertyPics\\").mkdirs(); // code for making order file in restaurant directory
File propertyInfo = new File("System\\Property Manager\\" + agentName + "\\Properties\\" + propertyID + "\\propertyInfo.txt"); //Adds order filename to names.txt file. Used to fetch order file names later.
FileWriter propertyFileWriter = new FileWriter(propertyInfo, false);
PrintWriter propertyPrintWriter = new PrintWriter(propertyFileWriter);
propertyPrintWriter.println(propertyID);
propertyPrintWriter.println(titileName);
propertyPrintWriter.println(price);
propertyPrintWriter.println(size);
propertyPrintWriter.println(propertyAddress.getProject());
propertyPrintWriter.println(propertyAddress.getFullAddress());
propertyPrintWriter.println(bedRoomsNum);
propertyPrintWriter.println(bathRoomsNum);
propertyPrintWriter.println(propertyType);
propertyPrintWriter.println(furnishing);
propertyPrintWriter.println(propertyActivationStatus);
propertyPrintWriter.println(propertyApprovalStatus);
for (String s : getAvailableFacilities()){ // split facilities / features using "|"
propertyPrintWriter.print(s + "|");
}
propertyPrintWriter.print("\n");
for (String s : getAvailableFeatures()){
propertyPrintWriter.print(s + "|");
}
propertyPrintWriter.print("\n");
propertyPrintWriter.println(description);
propertyPrintWriter.println(tenantName);
propertyPrintWriter.println(agentName);
propertyPrintWriter.close();
propertyFileWriter.close();
}
public String getTitileName() {
return titileName;
}
public void setTitileName(String titileName) {
this.titileName = titileName;
}
public int getPropertyID() {
return propertyID;
}
public void setPropertyID(int propertyID) {
this.propertyID = propertyID;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public String[] getPropertyPicturePath() {
return propertyPicturePath;
}
public void setPropertyPicturePath(String[] propertyPicturePath) {
this.propertyPicturePath = propertyPicturePath;
}
public Address getPropertyAddress() {
return propertyAddress;
}
public void setPropertyAddress(Address propertyAddress) {
this.propertyAddress = propertyAddress;
}
public int getBedRoomsNum() {
return bedRoomsNum;
}
public void setBedRoomsNum(int bedRoomsNum) {
this.bedRoomsNum = bedRoomsNum;
}
public int getBathRoomsNum() {
return bathRoomsNum;
}
public void setBathRoomsNum(int bathRoomsNum) {
this.bathRoomsNum = bathRoomsNum;
}
public String getPropertyType() {
return propertyType;
}
public void setPropertyType(String propertyType) {
this.propertyType = propertyType;
}
public String getFurnishing() {
return furnishing;
}
public void setFurnishing(String furnishing) {
this.furnishing = furnishing;
}
public String getPropertyActivationStatus() {
return propertyActivationStatus;
}
public void setPropertyActivationStatus(String propertyActivationStatus) {
this.propertyActivationStatus = propertyActivationStatus;
}
public String[] getAvailableFacilities() {
return availableFacilities;
}
public void setAvailableFacilities(String[] availableFacilities) {
this.availableFacilities = availableFacilities;
}
public String getPropertyApprovalStatus() {
return propertyApprovalStatus;
}
public void setPropertyApprovalStatus(String propertyApprovalStatus) {
this.propertyApprovalStatus = propertyApprovalStatus;
}
public String[] getAvailableFeatures() {
return availableFeatures;
}
public void setAvailableFeatures(String[] availableFeatures) {
this.availableFeatures = availableFeatures;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getTenantName() {
return tenantName;
}
public void setTenantName(String tenantName) {
this.tenantName = tenantName;
}
public String getAgentName() {
return agentName;
}
public void setAgentName(String agentName) {
this.agentName = agentName;
}
// calculate rent rate
public double getRentalRate() {
double rentalRate = price/ size;
BigDecimal bd = new BigDecimal(rentalRate).setScale(2, RoundingMode.HALF_UP);
return bd.doubleValue();
}
}