-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMember.java
More file actions
361 lines (340 loc) · 14.6 KB
/
Copy pathMember.java
File metadata and controls
361 lines (340 loc) · 14.6 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
import java.sql.*;
import java.util.*;
import java.sql.SQLException;
import java.text.ParseException;
public class Member{
static Scanner scan = new Scanner(System.in);
static int input = 0;
static ResultSet rs = null;
//Declaring and Instantiating all the attribute of a Member
static int memberID = -1;
static String firstName = "";
static String lastName = "";
static String level = "";
static String email = "";
static String phone = "";
static String address = "";
static boolean activeStatus = false;
static double rewardAmount = -1.00;
/**
* This method is called in the MainMenu file when the user wants to add/edit/delete/view members in the database.
* @throws ClassNotFoundException
* @throws SQLException
* @throws ParseException
*/
public static void memberMenu() throws ClassNotFoundException, SQLException, ParseException{
do{
System.out.println("Member Menu");
System.out.println();
System.out.println("0. Return to Information Processing Menu");
System.out.println("1. View All Members");
System.out.println("2. View Member by ID");
System.out.println("3. Add Member");
System.out.println("4. Edit Member");
System.out.println("5. Delete Member");
System.out.println();
System.out.println("Please choose an option from the menu: ");
input = scan.nextInt();
switch(input){
case 0:
System.out.println("Going back to Information Processing Menu");
return;
case 1:
viewAllMembers();
break;
case 2:
viewMember();
break;
case 3:
addMember();
break;
case 4:
editMember();
break;
case 5:
deleteMember();
break;
default:
System.out.println("Invalid input");
break;
}
input = -1;
} while(input != 0);
}
/**
* Method displays all members in the database
*/
public static void viewAllMembers() throws ClassNotFoundException, SQLException, ParseException{
try{
rs = MemberSQL.viewAllMembers();
printMember(rs);
}
catch(SQLException e){
System.out.println("SQL Exception");
e.getStackTrace();
}
}
/**
* Method displays information of a single member
*/
public static void viewMember() throws ClassNotFoundException, SQLException, ParseException {
do{
System.out.println("In order to go back to Member Menu, enter 0");
System.out.println("Please enter a member ID to view a member");
System.out.println();
System.out.println("Member ID: ");
input = scan.nextInt();
scan.nextLine();
if(input > 0){
rs = MemberSQL.viewMember(input);
printMember(rs);
rs.close();
} else if(input < 0){
System.out.println("Invalid input");
} else if(input == 0){
System.out.println("Going back to Member Menu");
return;
}
} while(input != 0);
}
/**
* Method adds a member's information to database by calling the addMember in the MemberSQl file
*/
public static void addMember() throws ParseException, ClassNotFoundException, SQLException{
//All the current attributes on the first iteration will be empty, as the user begins to fill in attributes
//of the member the display will be updated. Before the user selects 10, all the attributes must be filled
//so that the member can be created in the database.
do{
System.out.println("0. Go back to Member Menu: ");
System.out.println("1. Member ID: " + memberID);
System.out.println("2. First Name: " + firstName);
System.out.println("3. Last Name: " + lastName);
System.out.println("4. Level: " + level);
System.out.println("5. Email: " + email);
System.out.println("6. Phone: " + phone);
System.out.println("7. Address: " + address);
System.out.println("8. Active Status: " + activeStatus);
System.out.println("9. Reward Amount: " + rewardAmount);
System.out.println("10. After all attributes have been entered, select 10 to create the new member:");
System.out.println();
System.out.println("Select a number to add to member information: ");
input = scan.nextInt();
scan.nextLine();
updateAttributes(input, "a");
} while(input != 0);
rs.close();
}
/**
* Method edits a member's information to database by calling the editMember in the MemberSQl file
*/
public static void editMember() throws ParseException, ClassNotFoundException, SQLException{
int input = 0;
do{
System.out.println("In order to go back to Member Menu, enter 0");
System.out.println("Please enter a member ID to edit a member");
input = scan.nextInt();
scan.nextLine();
System.out.println();
//MemberID must be a number greater than 0 so that the application can search for that member.
if(input > 0){
rs = MemberSQL.viewMember(memberID);
//Checks if viewMember was able to find an existing Member
if(!rs.next()){
System.out.println("Member does not exist");
} else{
//The member exist and all the attributes of that member are being stored into variables so
//that they can be displayed to the user. In order for them to choose which attribute to edit.
memberID = rs.getInt("memberID");
firstName = rs.getString("firstName");
lastName = rs.getString("lastName");
level = rs.getString("level");
email =rs.getString("email");
phone = rs.getString("phone");
address = rs.getString("address");
activeStatus = rs.getBoolean("activeStatus");
rewardAmount = rs.getDouble("rewardAmount");
do{
//Attributes are displayed to the user and they must choose which one to edit.
//User will be reprompted these options until they decide to go back to Member Menu
System.out.println("0. Go back to Member Menu: ");
System.out.println("1. Member ID: " + memberID);
System.out.println("2. First Name: " + firstName);
System.out.println("3. Last Name: " + lastName);
System.out.println("4. Level: " + level);
System.out.println("5. Email: " + email);
System.out.println("6. Phone: " + phone);
System.out.println("7. Address: " + address);
System.out.println("8. Active Status: " + activeStatus);
System.out.println("9. Reward Amount: " + rewardAmount);
System.out.println("10. After all attributes have been entered, select 10 to edit member:");
System.out.println();
System.out.println("Select a number to edit member information: ");
input = scan.nextInt();
scan.nextLine();
updateAttributes(input, "e");
} while(input != 0);
}
}
}while(input != 0);
}
/**
* Method deletes a member's information in the database by calling the deleteMember in the MemberSQl file
*/
public static void deleteMember(){
do {
System.out.println("In order to go back to Member Menu, enter 0");
System.out.println("Please enter a member ID to delete a member");
System.out.println();
System.out.println("Member ID: ");
input = scan.nextInt();
if(input > 0){
MemberSQL.deleteMember(input);
} else if(input < 0){
System.out.println("Invalid input");
} else if (input ==0){
System.out.println("Going back to Member Menu");
return;
}
} while(input != 0);
}
/**
* Method is called in the MainMenu file under maintainBillingTransactions. This method will prompt user
* for member ID to be passed to rewardCheck in MemberSQL to generate the query.
*/
public static void rewardCheck() throws ParseException, ClassNotFoundException, SQLException{
do {
System.out.println("In order to go back to Billing Menu, enter 0");
System.out.println("Generate reward check for platinum member, enter 1");
input = scan.nextInt();
if(input == 0){
System.out.println("Going back to Billing Menu");
return;
} else if (input == 1){
System.out.println("In order to generate the reward check, please enter a memberID");
memberID = scan.nextInt();
rs = MemberSQL.rewardCheck(memberID);
if (rs == null) {
System.out.println("Member does not exist");
} else if(!rs.next()){
System.out.println("This member has no rewards");
} else{
System.out.println("Reward Check for Member " + memberID + ": $" + rs.getDouble("rewardAmount"));
}
} else{
System.out.println("Invalid input");
}
} while(input != 0);
}
/**
* Method is used in all the methods above to print out the information of a member. This method takes in
* a ResultSet and then prints out all the attributes each member of the ResultSet.
* @param rs
* @throws SQLException
*/
public static void printMember(ResultSet rs) throws SQLException{
if(!rs.next()){
System.out.println("There is no member with this memberID");
} else{
do{
memberID = rs.getInt("memberID");
firstName = rs.getString("firstName");
lastName = rs.getString("lastName");
level = rs.getString("level");
email = rs.getString("email");
phone = rs.getString("phone");
address = rs.getString("address");
activeStatus = rs.getBoolean("activeStatus");
rewardAmount = rs.getDouble("rewardAmount");
System.out.println("Member ID: " + memberID + ", first name: " + firstName + ", last name: " + lastName + ", level: "
+ level + ", email: " + email + ", phone: " + phone + ", address: " + address
+ ", active status: "+ activeStatus + ", reward amount: " + rewardAmount);
} while(rs.next());
}
}
/**
* This method is used to reset all the variables to "", 0, or false
*/
public static void resetAttributes(){
memberID = -1;
firstName = "";
lastName = "";
level = "";
email = "";
phone = "";
address = "";
activeStatus = false;
rewardAmount = -1.00;
}
/**
* From option that the user selects, this switch statement will prompt the user for the new value for
* specific attribute.
* Case 10 will take all the updated attributes and update the member in the query. Afterwards, it will
* reset all the variable fields to "" , 0, or false.
* @param input
* @param s
*/
public static void updateAttributes(int input, String s) throws ParseException, ClassNotFoundException, SQLException{
switch(input){
case 0:
System.out.println("Going back to Member Menu");
System.out.println();
resetAttributes();
break;
case 1:
System.out.println("Enter Member ID:");
memberID = scan.nextInt();
break;
case 2:
System.out.println("Enter First Name:");
firstName = scan.nextLine();
break;
case 3:
System.out.println("Enter Last Name:");
lastName = scan.nextLine();
break;
case 4:
System.out.println("Enter Level:");
level = scan.nextLine();
break;
case 5:
System.out.println("Enter Email:");
email = scan.nextLine();
break;
case 6:
System.out.println("Enter Phone:");
phone = scan.nextLine();
break;
case 7:
System.out.println("Enter Address:");
address = scan.nextLine();
break;
case 8:
System.out.println("Enter True or False for Active Status:");
activeStatus = Boolean.parseBoolean(scan.nextLine());
break;
case 9:
System.out.println("Enter Reward Amount:");
rewardAmount = scan.nextDouble();
break;
case 10:
try{
if(s.equals("e")){
MemberSQL.editMember(memberID, firstName, lastName, level, email, phone, address, activeStatus, rewardAmount);
}
else if(s.equals("a")){
MemberSQL.addMember(memberID, firstName, lastName, level, email, phone, address, activeStatus, rewardAmount);
}
} catch(SQLException e){
System.out.println("SQL Exception");
e.getStackTrace();
break;
}
rs = MemberSQL.viewMember(memberID);
printMember(rs);
resetAttributes();
break;
default:
System.out.println("Invalid input");
}
}
}