-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBTOProjectController.java
More file actions
197 lines (150 loc) · 7.55 KB
/
Copy pathBTOProjectController.java
File metadata and controls
197 lines (150 loc) · 7.55 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
package assignment2002;
import assignment2002.user.Manager;
import assignment2002.utils.BTOFileService;
import assignment2002.utils.Data;
import assignment2002.utils.DateCheck;
import assignment2002.utils.InputUtil;
import java.util.ArrayList;
import java.util.Scanner;
public class BTOProjectController {
private Manager manager;
private BTOEditController editContoller;
private final Scanner sc;
public BTOProjectController(Manager manager, Scanner sc){
this.manager = manager;
this.sc = sc;
editContoller = new BTOEditController(manager, sc);
}
public void showProjectMenu(){
System.out.println("\n=== MANAGE BTO PROJECTS ===");
System.out.println("1: Create BTO Project");
System.out.println("2: Edit BTO Project");
System.out.println("3: Delete BTO Project");
System.out.println("4: Back to Main Menu");
int mode = InputUtil.getValidatedIntRange(sc, "Choice ", 1, 4);
switch(mode){
case 1 -> createBTOMenu();
case 2 -> editContoller.editBTOMenu();
case 3 -> deleteBTOMenu();
case 4 -> System.out.println("Returning Back");
}
}
private void createBTOMenu(){
if (manager.isCurrentlyManaging(Data.btoList)) {
System.out.println("!!! UNABLE TO CREATE BTO !!!");
System.out.println("!!! CURRENTLY MANAGING ANOTHER PROJECT !!!");
return;
}
String twoRoom = "2-Room", threeRoom = "3-Room";
int twoRoomAmt = 0, twoRoomPrice = 0;
int threeRoomAmt = 0, threeRoomPrice = 0;
int officerSlot = 0;
String openDate, closeDate;
String projName;
while (true) {
projName = InputUtil.getNonEmptyString(sc, "Project Name: ");
if(manager.projNameExists(Data.btoList, projName)){
System.out.println("\n !!Duplicate Project Name");
System.out.println("Please Try Again");
continue;
} break;
}
// System.out.print("Neighbourhood: ");
String neighbourhood = InputUtil.getNonEmptyString(sc, "Neighbourhood: ");
System.out.println("=== Room Types ===");
System.out.println("1: 2 Room Only");
System.out.println("2: 3 Room Only");
System.out.println("3: 2 & 3 Room");
int roomVal = InputUtil.getValidatedIntRange(sc, "Room Choice: ", 1, 3);
switch (roomVal) {
case 1 ->{
System.out.println("=== 2-Room Only ===");
twoRoomAmt = InputUtil.getValidatedIntRange(sc, "Number of Units: ", 0, Integer.MAX_VALUE);
twoRoomPrice = InputUtil.getValidatedIntRange(sc, "Cost Per Unit: $", 0, Integer.MAX_VALUE);}
case 2 -> {
System.out.println("=== 3-Room Only ===");
threeRoomAmt = InputUtil.getValidatedIntRange(sc, "Number of Units: ", 0, Integer.MAX_VALUE);
threeRoomPrice = InputUtil.getValidatedIntRange(sc, "Cost Per Unit: $", 0, Integer.MAX_VALUE);}
case 3 -> {
System.out.println("=== 2 & 3 Rooms ===");
twoRoomAmt = InputUtil.getValidatedIntRange(sc, "[2-Room] Number of units available: ", 0, Integer.MAX_VALUE);
twoRoomPrice = InputUtil.getValidatedIntRange(sc, "[2-Room] Cost Per Unit: $ ", 0, Integer.MAX_VALUE);
threeRoomAmt = InputUtil.getValidatedIntRange(sc, "[3-Room] Number of units available: ", 0, Integer.MAX_VALUE);
threeRoomPrice = InputUtil.getValidatedIntRange(sc, "[3-Room] Cost Per Unit: $ ", 0, Integer.MAX_VALUE);}
default -> System.out.println("Try Again");
}
while(true){ //Ensures that closeDate must come after openDate
do {
System.out.print("Opening Date for HDB (MM/DD/YYYY): "); //Idk could be better
openDate = sc.nextLine(); //Leave these they are validated via dateValidator
} while (!DateCheck.dateValidator(openDate));
do {
System.out.print("Closing Date for HDB (MM/DD/YYYY): "); //Idk could be better
closeDate = sc.nextLine(); //Leave these they are validated via dateValidator
} while (!DateCheck.dateValidator(closeDate));
if(DateCheck.dateComparator(openDate, closeDate)){
break;
} else{
System.out.println("Error with Date Ranges");
System.out.println("Try Again\n");
}
}
officerSlot = InputUtil.getValidatedIntRange(sc, "Max Number of Officers (1 ~ 10): ", 1, 10);
System.out.println("== Visibility of Property ==");
System.out.println("Visible = Y");
System.out.println("Not Visible = N");
String visibleString = InputUtil.getConfirmationString(sc, "Choice");
switch (visibleString) {
case "TRUE" -> System.out.println("Visibility Selected: Visible");
case "FALSE" -> System.out.println("Visibility Selected: Not Visible");
default -> System.out.println("Invalid Input Try Again!");
}
System.out.printf("Project: %s Has Been Successfully Added\n", projName);
//APPEND LOGIC
String managerIC = manager.getName();
ArrayList<Manager> managerICRef = new ArrayList<>();
managerICRef.add(manager);
String formattedString = String.join("\t",
projName, neighbourhood, twoRoom, String.valueOf(twoRoomAmt), String.valueOf(twoRoomPrice),
threeRoom, String.valueOf(threeRoomAmt),String.valueOf(threeRoomPrice), openDate, closeDate,
managerIC, String.valueOf(officerSlot), "Empty", "Empty", "Empty", visibleString); //16 Total Inputs
manager.createBTOListing(Data.btoList, managerICRef, new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), formattedString);
BTOFileService.appendBTO(formattedString);
}
private void deleteBTOMenu(){
int choice;
BTOProperty propertyToDel;
System.out.println("Project List: ");
if (Data.btoList.isEmpty()) {
System.out.println("No projects available to delete.");
return;
}
// Show all projects with index
while(true){
for (int i = 0; i < Data.btoList.size(); i++) {
BTOProperty p = Data.btoList.get(i);
System.out.printf("%d. %s (%s)\n", i + 1, p.getProjectName(), p.getNeighbourhood());
}
choice = InputUtil.getValidatedIntRange(sc, "Enter the number of the project to delete (0 to cancel): ", 0, Data.btoList.size());
if(choice == 0){
return;
}
propertyToDel = Data.btoList.get(choice - 1);
System.out.println("=== Project DELETION Confirmation ===");
System.out.printf("Project Chosen: %s\n", propertyToDel.getProjectName());
System.out.printf("Project Neighbourhood: %s\n", propertyToDel.getNeighbourhood());
String confirm = InputUtil.getConfirmationString(sc, "Confirm ");
if (confirm.equalsIgnoreCase("false")){
continue;
}
break;
}
if(manager.deleteBTOListing(Data.btoList, propertyToDel)){
System.out.println("Project deleted successfully.");
BTOFileService.removeBTO(propertyToDel.getProjectName());
} else{
System.out.println("An error has occurred");
return;
}
}
}