-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBonusMemberUI.java
270 lines (217 loc) · 7.64 KB
/
BonusMemberUI.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
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
package no.ntnu.idata.iir.Joachiam.oblig3;
import java.time.LocalDate;
import java.util.Scanner;
/**
* Represents the user interface for bonusMembers.
*
* Credits to Simen og Olav for "Borrowed" methods.
*
*
*
*
*/
public class BonusMemberUI {
private MemberArchive members;
private final int ADD_BONUS_MEMBER = 1;
private final int LIST_ALL_MEMBERS = 2;
private final int UPGRADE_QUALIFIED_MEMBERS = 3;
private final int REGISTER_BONUS_POINTS = 4;
private final int LIST_BY_POINTS = 5;
private static final int ADD_TEST_MEMBERS = 8;
private final int QUIT = 6;
public BonusMemberUI() { members = new MemberArchive();}
/**
* Handles user input to designed functions of the application.
*
*
* @return
*/
private int menuChoice(){
int menuChoice = 0;
Scanner sc = new Scanner(System.in);
menuChoice = sc.nextInt();
sc.nextLine();
return menuChoice;
}
private void start() {
boolean running = true;
while (running) {
System.out.println("Welcome the Bonus Member UI");
System.out.println("1. Add bonus member");
System.out.println("2. List all members");
System.out.println("3. Upgrade qualified members");
System.out.println("4. Register bonus points");
System.out.println("5. List all members by points");
System.out.println("8. Add test Members");
System.out.println("6. Quit");
int menuChoice = menuChoice();
switch (menuChoice) {
case ADD_BONUS_MEMBER:
addBonusMember();
break;
case LIST_ALL_MEMBERS:
listAllMembers();
break;
case UPGRADE_QUALIFIED_MEMBERS:
upgradeQualifiedMembers();
break;
case REGISTER_BONUS_POINTS:
registerBonusPoints();
break;
case LIST_BY_POINTS:
listAllMembersByPoints();
break;
case ADD_TEST_MEMBERS:
System.out.println("Adding test members to archive.");
addTestMembers();
break;
case QUIT:
System.out.println("Thanks for using the app!");
running = false;
}
}
}
/**
* Users sorted in order of amount of points gained
*
*
*/
private void listAllMembersByPoints() {
members.stream()
.sorted()
.forEach(this::printMemberDetails);
}
/**
* Handles the adding of points to a desired user
*
*
*/
private void registerBonusPoints() {
int memberNumber = 0;
int points = 0;
System.out.println("Register Bonus Points:");
System.out.println("Enter the member number of the desired member");
Scanner sc = new Scanner(System.in);
memberNumber = sc.nextInt();
sc.nextLine();
System.out.println("Enter the amount of points to add");
points = sc.nextInt();
sc.nextLine();
members.registerPoints(memberNumber, points);
// members.registerPoints(int memberNumber, int bonusPoints);
}
/**
* Upgrades the members withing the required range of points
* for either silver or Gold.
*
*/
private void upgradeQualifiedMembers() {
int year = 0;
int month = 0;
int day = 0;
System.out.println("Upgrade qualified members");
System.out.println("Enter the date");
System.out.println("Year");
Scanner sc = new Scanner(System.in);
System.out.println("Enter the year");
year = sc.nextInt();
sc.nextLine();
System.out.println("Enter the month");
month = sc.nextInt();
sc.nextLine();
System.out.println("Enter the day");
day = sc.nextInt();
sc.nextLine();
members.checkMembers(LocalDate.of(year, month, day));
}
/**
* Prints a list of all the members in the collection
*
*/
private void listAllMembers(){
members.forEach(this::printMemberDetails);
}
/**
* Adds Bonus member to the archive
*
*
*/
private void addBonusMember() {
String firstName = "";
String lastName = "";
String emailAddress = "";
String password = "";
int year = 0;
int month = 0;
int day = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Please enter first name");
firstName = sc.nextLine();
System.out.println("Please enter last name");
lastName = sc.nextLine();
System.out.println("Please enter email address");
emailAddress = sc.nextLine();
System.out.println("Please enter password");
password = sc.nextLine();
System.out.println("Please enter current year");
year = sc.nextInt();
sc.nextLine();
System.out.println("Please enter current month");
month = sc.nextInt();
sc.nextLine();
System.out.println("Please enter current day");
day = sc.nextInt();
sc.nextLine();
Personals newPerson = new Personals(firstName, lastName, emailAddress, password);
members.addMember(newPerson, LocalDate.of(year, month, day));
}
/**
* Prints the member details to the console
*
* @param bonusMember
*/
private void printMemberDetails(BonusMember bonusMember){
System.out.println("Name:" + bonusMember.getPersonals().getFirstname()
+ " " + bonusMember.getPersonals().getSurname());
System.out.println("Points: " + bonusMember.getPoints());
System.out.println("Member number: " + bonusMember.getMemberNo());
System.out.println("Member type: " + bonusMember.getMembershipLevel());
System.out.println("");
}
/**
* Go baby go!
*
* @param args
*/
public static void main(String[] args) {
BonusMemberUI bui = new BonusMemberUI();
bui.start();
}
/**
* Adds test members to the members archive. Ment for testing purpose
*
*
*/
private void addTestMembers() {
LocalDate oleEnrollDate = LocalDate.of(2006, 2, 15);
LocalDate toveEnrollDate = LocalDate.of(2007, 5, 3);
LocalDate liseEnrollDate = LocalDate.of(2008, 2, 10);
LocalDate jonasEnrollDate = oleEnrollDate; //same date as Ole
LocalDate erikEnrollDate = LocalDate.of(2007, 3, 1);
Personals ole = new Personals("Ole", "Olsen",
"[email protected]", "ole");
Personals tove = new Personals("Tove", "Hansen",
"[email protected]", "tove");
Personals lise = new Personals("Lise", "Lisand",
"[email protected]", "lise");
Personals jonas = new Personals("Jonas", "Johnsen",
"[email protected]", "jonny");
Personals erik = new Personals("Erik", "Eriksen",
"[email protected]", "rikkenrules");
members.addMember(ole, oleEnrollDate);
members.addMember(tove, toveEnrollDate);
members.addMember(lise, liseEnrollDate);
members.addMember(jonas, jonasEnrollDate);
members.addMember(erik, erikEnrollDate);
}
}