-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckInGUI.java
More file actions
364 lines (309 loc) · 11.8 KB
/
Copy pathCheckInGUI.java
File metadata and controls
364 lines (309 loc) · 11.8 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
//import all the GUI classes
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//GUI Frame for FlightList and PassengerList
public class CheckInGUI extends JFrame implements ActionListener {
//The flight and passenger lists to be searched.
private FlightList flightList;
private PassengerList passengerList;
private Passenger foundPassenger;
private double fee1;
private double fee2;
private boolean cIn;
/**
* GUI components
*/
JTextField result1, result2, result3;
JTextField searchField1, searchField2;
JTextField bookingRefPanel, lastnamePanel, weightPanel, heightPanel, widthPanel, lengthPanel;
JButton search1, search2;
JButton enterVolume, enterWeight;
JScrollPane scrollList;
JButton checkIn, close;
JTextArea resultPassengers, resultFees;
/**
*Create the frame with its panels
*@param flist The flight list to be searched
*@param plist The passenger list to be serarche
*/
public CheckInGUI(FlightList flist, PassengerList plist) {
this.flightList = flist;
this.passengerList = plist;
//set up window title
setTitle("Welcome to Self-Service Check in");
//disable standard close button
setDefaultCloseOperation(this.DO_NOTHING_ON_CLOSE);
setupSouthPanel();
setupCenterPanel();
setupNorthPanel();
//pack and set visible
pack();
setVisible(true);
}
/**
* Creates the North panel
*/
private void setupNorthPanel() {
//search panel contains label, text field and button FOR PASSENGER LIST
JPanel northPanel = new JPanel(new GridLayout(2,5));
JPanel searchPanel1 = new JPanel();
searchPanel1.setLayout(new GridLayout(1,5));
searchPanel1.add(new JLabel("Booking Reference:"));
searchField1 = new JTextField(5);
searchPanel1.add(searchField1);
searchPanel1.add(new JLabel("Last Name:",SwingConstants.RIGHT));
searchField2 = new JTextField(5);
searchPanel1.add(searchField2);
search1 = new JButton("Search");
searchPanel1.add(search1);
//specify action when button is pressed
search1.addActionListener(this) ;
//Set up the area where the results will be displayed.
result1= new JTextField(25);
result1.setEditable(false);
//set up north panel containing 2 previous areas
northPanel.add(searchPanel1);
northPanel.add(result1);
//add north panel to the content pane
this.add(northPanel, BorderLayout.NORTH);
}
/**
* Creates the Center panel
*/
private void setupCenterPanel() {
//Set Volume Panel
JPanel volumePanel = new JPanel();
volumePanel.setLayout(new GridLayout(3,3));
volumePanel.add(new JLabel("Height (cm):",SwingConstants.RIGHT));
heightPanel = new JTextField(5);
volumePanel.add(heightPanel);
volumePanel.add(new JLabel(""));
volumePanel.add(new JLabel("Width (cm):",SwingConstants.RIGHT));
widthPanel = new JTextField(5);
volumePanel.add(widthPanel);
enterVolume = new JButton("Enter Dimensions");
enterVolume.addActionListener(this);
volumePanel.add(enterVolume);
volumePanel.add(new JLabel("Length (cm):",SwingConstants.RIGHT));
lengthPanel = new JTextField(5);
volumePanel.add(lengthPanel);
//volumePanel.add(new JLabel(""));
//Set Weight Panel
JPanel wPanel = new JPanel();
wPanel.setLayout(new GridLayout(1,3));
wPanel.add(new JLabel("Weight (kg):", SwingConstants.RIGHT));
weightPanel = new JTextField(5);
wPanel.add(weightPanel);
enterWeight = new JButton("Enter Weight");
enterWeight.addActionListener(this);
wPanel.add(enterWeight);
//Setup main Center Panel
JPanel centerPanel = new JPanel();
centerPanel.setLayout(new GridLayout(6,1));
centerPanel.add(new JLabel("Enter Baggage Dimensions",SwingConstants.CENTER));
centerPanel.add(volumePanel);
result2= new JTextField(25);
result2.setEditable(false);
centerPanel.add(result2);
centerPanel.add(new JLabel("Enter Baggage Weight", SwingConstants.CENTER));
centerPanel.add(wPanel);
result3= new JTextField(25);
result3.setEditable(false);
centerPanel.add(result3);
//Add Panel to Layout
this.add(centerPanel, BorderLayout.CENTER);
}
/**
* Creates the South panel
*/
private void setupSouthPanel() {
JPanel southPanel = new JPanel(new GridLayout(2,5));
//Check-In Button
checkIn = new JButton("Check in");
checkIn.addActionListener(this);
//Close Button
close = new JButton("Close");
close.addActionListener(this);
//Add buttons to South Pane
southPanel.add(checkIn);
southPanel.add(close);
//add south panel to the content pane
this.add(southPanel, BorderLayout.SOUTH);
}
/**
*Sets up the method for calculating baggage volume
*If the volume is over the limit it shows the applied fee
*Catches trying to convert a String to a double
*/
private void bagVolIn() {
String heightString = heightPanel.getText().trim();
String widthString = widthPanel.getText().trim();
String lengthString = lengthPanel.getText().trim();
if (foundPassenger != null) {
if (heightString.length() > 0 && widthString.length() > 0 && lengthString.length() > 0) {
try {
double height = Double.parseDouble(heightString);
double width = Double.parseDouble(widthString);
double length = Double.parseDouble(lengthString);
double volume = height * width * length/1000000;
foundPassenger.setBagVolume(volume);
if (volume <= 0.3) {
fee1 = foundPassenger.feeByVol(volume);
result2.setText("Baggage volume within limits. No oversize fee added.");
}
else {
fee1 = foundPassenger.feeByVol(volume);
String text1 = "Baggage volume exceeded, £" + fee1 + " fee applied.";
result2.setText(text1);
}
}
catch (NumberFormatException nfe) {
result2.setText("Please give a valid number for all measurements.");
}
}
else {
result2.setText("Missing baggage measurements.");
}
}
else {
result2.setText("Please enter passenger details.");
}
}
/**
*Sets up the method for entering the baggage weight
*If the weight is over the limit it shows the applied fee
*Catches trying to convert a String to double
*/
private void bagWeightIn() {
String weightString = weightPanel.getText().trim();
if (foundPassenger != null) {
if (weightString.length() > 0) {
try {
double weight = Double.parseDouble(weightString);
foundPassenger.setBagWeight(weight);
if (weight <= 20) {
fee2 = foundPassenger.feeByWeight(weight);
result3.setText("Baggage weight within limits. No overweight fee added.");
}
else {
fee2 = foundPassenger.feeByWeight(weight);
String text2 = "Baggage weight exceeded, £" + fee2 + " fee applied.";
result3.setText(text2);
}
}
catch (NumberFormatException nfe) {
result3.setText("Please give a valid number for the weight.");
}
}
else {
result3.setText("Weight not entered.");
}
}
else {
result3.setText("Please enter passenger details.");
}
}
private void search() {
//get search text and search staff list
//setting result text
String searchString1 = searchField1.getText().trim();
String searchString2 = searchField2.getText().trim();
if(searchString1.length() > 0 && searchString2.length() > 0) {
Passenger person = passengerList.findPassenger(searchString1, searchString2);
if (person != null ) {
if (person.getCheckedIn() == false) {
String fCode = person.getFlightCode();
String destination = flightList.findByFlightCode(fCode).getDestination();
result1.setText("Passenger: " + person.getPassengerName().getFullName()+ ". Flight " + fCode + ". Destination: " + destination + ".");
foundPassenger = person;
} else {
result1.setText("Passenger already checked in");
searchField1.setText("");
searchField2.setText("");
foundPassenger = null;
}
//gobf.disableButton(person.getName().getFirstName());
} else
result1.setText("Passenger not found.");
} else if (searchString1.length() == 0 && searchString2.length() > 0) {
result1.setText("No Booking Reference given.");
} else if (searchString1.length() > 0 && searchString2.length() == 0) {
result1.setText("No Last Name given.");
} else
result1.setText("Please enter Booking Reference and Last Name.");
}
/**
*Sets the method for checking in
*If baggage volume or weigth is exceeded, it shows the total payable fee
*/
private void checkIn() {
foundPassenger.setFee(fee1+fee2);
foundPassenger.checkIn();
if (fee1+fee2 == 0) {
result3.setText("Passenger correctly checked in with no additional fees. Have an excellent flight!");
}
else {
result3.setText("Passenger correctly checked in with a total fee of: £" + (fee1+fee2) + ". Have an excellent flight!");
}
result1.setText("");
result2.setText("");
searchField1.setText("");
searchField2.setText("");
heightPanel.setText("");
widthPanel.setText("");
lengthPanel.setText("");
weightPanel.setText("");
}
/**
* Set up the action events
* After clicking any action button by the user the
* GUI gives an output
*/
public void actionPerformed(ActionEvent e) {
if (e.getSource() == search1) {
//displayList.setText("Search");
search();
result2.setText("");
result3.setText("");
}
else if (e.getSource() == enterVolume) {
//displayList.setText("Search");
bagVolIn();
}
else if (e.getSource() == enterWeight) {
//displayList.setText("Search");
bagWeightIn();
}
else if (e.getSource() == checkIn) {
String heightString = heightPanel.getText().trim();
String widthString = widthPanel.getText().trim();
String lengthString = lengthPanel.getText().trim();
String weightString = weightPanel.getText().trim();
if (foundPassenger != null && heightString.length() > 0 && widthString.length() > 0 && lengthString.length() > 0 && weightString.length() > 0) {
checkIn();
}
else {
result3.setText("Check In failed");
}
}
else if (e.getSource() == close) {
flightList.writeFlightReport("FlightReport.txt");
JOptionPane.showMessageDialog(this,
"FlightReport.txt was successfully created.");
System.exit(0);
}
/*
else if (e.getSource() == close) {
//show 'end of program' before closing file
JOptionPane.showMessageDialog(this,
"Do 'end of program' things instead of showing this");
//get the report with short detail from competitor list
String report = flightList.getFlightReport();
//Write the report to a text file 'Allcompetitor_report.txt'
flightList.readFile("Allflight_report.txt", report);
System.exit(0);
}
*/
}
}