Added some extra stuff. Gonna take a day off after all this shit.
- Author
- Vngngdn
- Date
- Dec. 16, 2016, 8:49 a.m.
- Hash
- 6be1f9e57b06e831fecffc73592e96a65c728220
- Parent
- f5432883ce7c309c501db3356376950db2e8be5f
- Modified files
- Challenge 6/SearchView.java
- nextChallenge.md
Challenge 6/SearchView.java ¶
6 additions and 2 deletions.
View changes Hide changes
1 |
1 |
import java.util.ArrayList; |
2 |
2 |
import java.util.Date; |
3 |
3 |
|
4 |
4 |
/** |
5 |
5 |
* Class for creating a screen that allows querying actions. |
6 |
6 |
* This program offers the ability to search in the program for Reservations, |
7 |
7 |
* Room status, etc. |
8 |
8 |
* This class creates a GUI for user interaction. |
9 |
9 |
* When matches are found, it will display them. In case of a unique match, that |
10 |
10 |
* match is immediately displayed. |
11 |
11 |
* @see ReservationView |
12 |
12 |
* @author Maarten Vangeneugden - 1438256 |
13 |
13 |
*/ |
14 |
14 |
public class SearchView { |
15 |
15 |
private ReservationController rc; |
16 |
16 |
private RoomController roc; |
17 |
17 |
private Window window; |
18 |
18 |
|
19 |
19 |
private JTextField groupNameField; |
20 |
20 |
private JTextField reservationIDField; |
21 |
21 |
private JTextField beginDateField; |
22 |
22 |
private JTextField endDateField; |
23 |
23 |
private JTextField breakfastDayField; |
24 |
24 |
|
25 |
25 |
public SearchView(ReservationController rc, RoomController roc) { |
26 |
26 |
this.rc = rc; |
27 |
27 |
this.roc = roc; |
28 |
28 |
|
29 |
29 |
this.window = new Window("Search screen"); |
30 |
30 |
this.addFields(); |
31 |
31 |
} |
32 |
32 |
|
33 |
33 |
private void addFields() { |
34 |
34 |
// TODO: Add fields to private members! |
35 |
35 |
this.window.createLabel("Search reservations:"); |
36 |
36 |
this.groupNameField = this.window.createTextField("Search by group name"); |
37 |
37 |
this.reservationIDField = this.window.createTextField("Search by reservation ID"); |
38 |
38 |
this.window.createButton("Search reservation", "", "queryReservations", this); |
39 |
39 |
this.window.createLabel("Search reserved beds in period (begin-end):"); |
40 |
40 |
this.beginDateField = this.window.createTextField(new Date().toGMTString()); |
41 |
41 |
this.endDateField = this.window.createTextField(new Date().toGMTString()); |
42 |
42 |
this.window.createButton("Get reserved beds", "", "queryBeds", this); |
43 |
43 |
this.window.createLabel("Find amount of breakfasts:"); |
44 |
44 |
this.breakfastDayField = this.window.createTextField(new Date().toGMTString()); |
45 |
45 |
this.window.createButton("Get breakfasts on given day", "", "queryBreakfasts", this); |
46 |
46 |
} |
47 |
47 |
|
48 |
48 |
public void queryReservations() { |
49 |
49 |
ArrayList<Reservation> foundReservations = new ArrayList<>(); |
50 |
50 |
String nameQuery = this.groupNameField.getText(); |
51 |
51 |
String IDQuery = this.reservationIDField.getText(); |
52 |
52 |
for(Reservation activeReservation : this.rc.getReservations()) { |
53 |
53 |
if(activeReservation.getGroupName().contains(nameQuery) && |
54 |
54 |
String.valueOf(activeReservation.getReservationID()).contains(IDQuery)) { |
55 |
55 |
foundReservations.add(activeReservation); |
56 |
56 |
} |
57 |
57 |
} |
58 |
58 |
// After collecting all results, offer the user the choice about which |
59 |
59 |
// one to take: |
60 |
60 |
String[] reservationNames = new String[foundReservations.size()]; |
61 |
61 |
for(int i=0; i<foundReservations.size(); i++) { |
62 |
62 |
String text = foundReservations.get(i).getGroupName() +" ("+ |
63 |
63 |
String.valueOf(foundReservations.get(i).getReservationID()) +")"; |
64 |
64 |
reservationNames[i] = text; |
65 |
65 |
} |
66 |
66 |
int choice = this.window.choiceDialog("Multiple results were found. Specify which one you want to view:", reservationNames); |
67 |
67 |
if(choice == -1) { // No result found |
68 |
68 |
this.window.messageDialog("No reservations matched the given details."); |
69 |
69 |
} |
70 |
70 |
else { |
71 |
71 |
new ReservationView(foundReservations.get(choice), this.rc, this.roc); |
72 |
72 |
} |
73 |
73 |
} |
74 |
74 |
|
75 |
75 |
public void queryBeds() { |
76 |
76 |
// The amount of reserved Beds is determined by the Reservations. |
77 |
77 |
// If a Reservation (partially) overlaps with the given time, then this |
78 |
78 |
// Bed is reserved in the given period. |
79 |
79 |
Date beginDate = new Date(this.beginDateField.getText()); |
80 |
80 |
Date endDate = new Date(this.endDateField.getText()); |
81 |
81 |
String result = ""; |
82 |
82 |
for(Reservation reservation: this.rc.getReservations()) { |
83 |
83 |
if(! |
84 |
84 |
(reservation.getBeginDate().before(beginDate) && reservation.getEndDate().before(beginDate)) || |
85 |
85 |
(reservation.getBeginDate().after(endDate) && reservation.getEndDate().after(endDate))) |
86 |
86 |
{ // This block is only reached if the valid options didn't match. |
87 |
87 |
String name = reservation.getGroupName(); |
88 |
88 |
String beds = String.valueOf(reservation.getReservedBeds().size()); |
89 |
89 |
String begin = reservation.getBeginDate().toGMTString(); |
90 |
90 |
String end = reservation.getEndDate().toGMTString(); |
91 |
91 |
result = result + |
92 |
92 |
name +" reserved "+ beds +" between "+ begin +" and "+ end +".\n"; |
93 |
93 |
} |
94 |
94 |
|
95 |
- | |
96 |
- | } |
+ |
95 |
if(!result.isEmpty()) { |
+ |
96 |
this.window.messageDialog(result); |
+ |
97 |
} |
+ |
98 |
else { |
+ |
99 |
this.window.messageDialog("No beds have reservation periods overlapping with the given timespan."); |
+ |
100 |
} |
97 |
101 |
|
98 |
102 |
public void queryBreakfasts() { |
99 |
103 |
|
100 |
104 |
} |
101 |
105 |
} |
102 |
106 |
nextChallenge.md ¶
53 additions and 0 deletions.
View changes Hide changes
+ |
1 |
============ |
+ |
2 |
|
+ |
3 |
Maak een programma om een jeugdherberg te beheren. |
+ |
4 |
|
+ |
5 |
Kamers |
+ |
6 |
------ |
+ |
7 |
- Kamers hebben een bepaald aantal bedden |
+ |
8 |
- Kamers kunnen faciliteiten hebben (bv. Airco, douche, bad, ...) |
+ |
9 |
- Kamers zijn van een bepaald type: Mannen, Vrouwen, of gemengd. |
+ |
10 |
|
+ |
11 |
Reserveringen |
+ |
12 |
------------- |
+ |
13 |
- Reserveringen bestaan uit: |
+ |
14 |
- Groepsnaam |
+ |
15 |
- # personen |
+ |
16 |
- Gewenste faciliteiten |
+ |
17 |
- Gewenste type |
+ |
18 |
- Ontbijt (optioneel, op alle dagen, of op bepaalde dagen) |
+ |
19 |
- Datum van aankomst |
+ |
20 |
- Verblijfsduur (== datum van vertrek) |
+ |
21 |
- Reserveringen gebeuren op basis van bedden, niet per sé op kamer |
+ |
22 |
- Reserveringen moeten kunnen worden aangepast en geannuleerd (zie "Zoeken") |
+ |
23 |
- Reserveringen krijgen een unieke ID |
+ |
24 |
|
+ |
25 |
Prijsberekening |
+ |
26 |
--------------- |
+ |
27 |
- Alle bedden kosten hetzelfde, maar onderhevig aan hoog-, midden- en |
+ |
28 |
laagseizoen |
+ |
29 |
- Elk ontbijt kost een supplement (--> ontbijt voor 4 man = 4 ontbijten) |
+ |
30 |
- Als een groep een hele kamer zelf afhuurt, 10% korting op totaalprijs |
+ |
31 |
|
+ |
32 |
Wijze van plaatsing |
+ |
33 |
------------------- |
+ |
34 |
- Bij reservatie: controleren of groep niet bij een deels bezette kamer gezet |
+ |
35 |
kan worden. |
+ |
36 |
- Indien niet mogelijk: Dan pas in nieuwe kamer plaatsen |
+ |
37 |
|
+ |
38 |
Zoeken |
+ |
39 |
------ |
+ |
40 |
Op basis van een gegeven tijdspanne: |
+ |
41 |
- Kunnen opzoeken hoeveel ontbijtjes gevraagd zijn op bepaalde dagen |
+ |
42 |
- Reserveringen kunnen opzoeken (ook op basis van groepsnaam en ID) |
+ |
43 |
- Kunnen opzoeken welke bedden in de gegeven tijdspanne gereserveed zijn |
+ |
44 |
|
+ |
45 |
Overig |
+ |
46 |
------ |
+ |
47 |
- Contractueel programmeren ("In Engels") |
+ |
48 |
- Alles in Java, en dus ook OOP =( |
+ |
49 |
- "Schrijf duidelijke, uitbreidbare, robuuste code" |
+ |
50 |
- Bij elke class @author vermelden |
+ |
51 |
- Ontwerpkeuzes; uitleggen hoe dat ge bovenstaande vereisten tegemoet komt |
+ |
52 |
- Documenteer code waar nodig |
+ |
53 |