-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumberCollegeAdmissionsV2.java
More file actions
345 lines (244 loc) · 12.5 KB
/
Copy pathHumberCollegeAdmissionsV2.java
File metadata and controls
345 lines (244 loc) · 12.5 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
import java.util.Arrays;
import java.util.Scanner;
public class HumberCollegeAdmissionsV2 {
public static void main(String args[]) {
//**STEVE: introduce program, cover until line 18
System.out.printlin("Welcome to the jungle")
System.out.println("Welcome to Humber College");
Scanner input = new Scanner(System.in);
System.out.println("Please enter a username: "); //prompt user to enter a username
String username = input.nextLine();
System.out.println("Thank you " + username + ", please enter a password:");
//**SANDRA: cover until line 25 in main method, go into detail about passwordValidation method BEFORE discussing line 24
String humber_password = input.nextLine();
if(passwordValidation(humber_password)){ //check if the password is valid using humber_password as an argument for passwordValidation
// if passwordValidation evaluates to true, program continues, otherwise program terminates
System.out.println("Thank you " + username + ", please enter the number of students: "); // asking user for number of students
}
//**MARIANA: cover until line 31 in main method, go into detail about numberValidation method BEFORE discussing line 31
int student_num = numberValidation(input.nextInt()); //calling validNum method on user input and storing result in student_num variable
System.out.println(student_num);
//**STEVE: cover until line 36 of main method, go into detail about nameList method BEFORE discussing line 36
String[] student_list = nameList(student_num); // creating 1D string array the store each students name using nameList method, student_num as argument
System.out.println(Arrays.toString(student_list)); //Arrays.toString allows us to print user-readable string array of student_list
//**UMAR: cover until line 43 of main method, go into detail about studentGrades method BEFORE discussing line 43
System.out.println("Please enter the grades (0-100) for each student.");
int[][] student_grades = studentGrades(student_list); //creating a 2D integer array to store each students grades using studentGrades method
System.out.println(Arrays.deepToString(student_grades)); //Arrays.deepToString converts the array to a user-readable string array
//**MALIK: cover until line 49 in main method, go into detail about studentGpaNum method BEFORE discussing line 49
System.out.println(" "); // these lines are just to ensure that the output has some space between lines
int[][] gpa_scores = studentGpaNum(student_grades); //creating 2D array of gpa_scores by calling studentGpaNum method on student_grades
System.out.println(Arrays.deepToString(gpa_scores));
//**HENRY: cover until line 55 of main method, go into detail of schoolList method and then schoolReport method afterwards to discuss output
System.out.println(" ");
String[][] acceptance_list = schoolList(gpa_scores, student_list); //call schoolList method on gpa_scores and student_list
schoolReport(acceptance_list); //school report method to get a more user friendly report of which school each student got accepted into (or none at all)
//**STEVE: will cover the rest of the program
System.out.println(" ");
int[] school_totals = acceptedList(acceptance_list);
acceptanceReport(school_totals); // report for the number of each students accepted in total as well as for each school
System.out.println(" ");
notAccepted(acceptance_list); // total number of students not accepted into Humber
System.out.println(" ");
highestGpaSchool(acceptance_list, gpa_scores); //method prints the student with the highest GPA in each school (as well as amongst those not accepted)
input.close();
}
public static Boolean passwordValidation(String humber_password) {
Scanner input = new Scanner(System.in);
int attempt = 0;
Boolean valid_password = false;
while(attempt < 3){ //while loop contains a for loop for accumulators but also conditional statements to assess password criteria
attempt++;
int upper_letter = 0;
int num = 0;
int spec_char = 0;
for(int index = 0; index < humber_password.length(); index++) {
if (Character.isDigit(humber_password.charAt(index))) {
num += 1; //the number of digits in the password
}
else if(Character.isUpperCase(humber_password.charAt(index))) {
upper_letter += 1; //the number of uppercase letters in the password
}
else if(!Character.isLetterOrDigit(humber_password.charAt(index))) {
spec_char += 1; //the number of special characters in the password
}
}
if((humber_password.length() >= 10 && (num == 2 || num == 3) && upper_letter >= 1 && spec_char == 1)) {
valid_password = true; //assuming all criteria are met, valid_password evaluates to true and program breaks out of loop
}
else if(attempt < 3) {
System.out.println("You only have " + (3 - attempt) + " attempts left. Please enter a VALID password: ");
humber_password = input.next(); //assuming one or more of the criteria are not met, the user has 2 more chances (iterations through the loop) to enter
// the correct password
}
else{
System.out.println("Sorry, you have run out of attempts. This program is terminating now.");
System.exit(0); //assuming 3 incorrect attempts in a row, program terminates
}
}
return valid_password; //returns value of valid_password
}
public static int numberValidation(int number){
int attempt = 0;
Scanner input = new Scanner(System.in);
while (attempt < 3){
attempt++; // attempt = 0
if(number >= 1 && number <= 50) {
System.out.println("Correct number:");
break;
}
else if (attempt < 3) {
System.out.println("Please enter correct number of students [ Attempt left : "+ (3 - attempt) + "]");
number = input.nextInt();
} else {
System.out.println("No attempts left");
System.exit(0);
}
}
return number;
}
public static String[] nameList(int student_num) {
Scanner input = new Scanner(System.in);
int count = 0; // accumulator
String[] student_names = new String[student_num]; //ensuring the list is the same length as the number provided
for(count = 0; count < student_num; count++) { //iterating through count as long as it is less than student_num
System.out.println("Please enter a name: ");
student_names[count] = input.nextLine(); //enter the names with spaces until count is equal to student_num
}
return student_names; //return user readable array of names
}
public static int[][] studentGrades(String[] student_names){
int[][] grades_list = new int[student_names.length][7];
Scanner input = new Scanner(System.in);
for(int student = 0; student < grades_list.length; student++) {
grades_list[student][0] = student; // we code the first column as a numeric representation (student number) of each person, from 0 onwards.
System.out.println("Please enter the grades (0-100) of " + student_names[student] + ".");
System.out.println("Input " + student_names[student] + "'s mark in Math: "); // For each student, we prompt the user to enter grades
grades_list[student][1] = input.nextInt(); // iterating through each student, a grade replaces default
// value of 0 when each grade is entered
System.out.println("Input " + student_names[student] + "'s mark in Science: ");
grades_list[student][2] = input.nextInt();
System.out.println("Input " + student_names[student] + "'s mark in Language: ");
grades_list[student][3] = input.nextInt();
System.out.println("Input " + student_names[student] + "'s mark in Drama: ");
grades_list[student][4] = input.nextInt();
System.out.println("Input " + student_names[student] + "'s mark in Music: ");
grades_list[student][5] = input.nextInt();
System.out.println("Input " + student_names[student] + "'s mark in Biology: ");
grades_list[student][6] = input.nextInt();
}
return grades_list; //finally, the method returns the final array with student number in first column, then math grade, science grade, etc.
}
public static int[][] studentGpaNum(int[][] student_marks){
int[][] GPA_list = new int[student_marks.length][2];
for(int student = 0; student < student_marks.length; student++) {
GPA_list[student][0] = student; // keeping the numeric representation of students
GPA_list[student][1] = (student_marks[student][1] * 4 + // we are multiplying the grades by the weight/course hours for each subject
student_marks[student][2] * 5 +
student_marks[student][3] * 4 +// we then add all values together
student_marks[student][4] * 3 +
student_marks[student][5] * 2 +
student_marks[student][6] * 4) / 22; //Finally, we divide by total number of credit hours, using parentheses to enforce
// desired order of operations
}
return GPA_list; // returns the array of student numbers and their gpa scores
}
public static String[][] schoolList(int[][] gpa, String[] names){
String[][] acceptance_list = new String[names.length][2];
for(int student = 0; student < names.length; student++) {
acceptance_list[student][0] = names[student]; //for each student, we get their name and add it to the acceptance_list array in first
// index
if(gpa[student][1] >= 90 && gpa[student][1] <= 100) {
acceptance_list[student][1] = "School of Engineering"; //We check the Gpa for 4 different scenarios, GPA greater or equal to 90
} // means the student gets accepted to Engineering
else if(gpa[student][1] >= 80) {
acceptance_list[student][1] = "School of Business";
}
else if(gpa[student][1] >= 70) {
acceptance_list[student][1] = "Law School";
}
else {
acceptance_list[student][1] = "Not accepted";
}
}
return acceptance_list;
}
public static int[] acceptedList(String[][] school_list){
int[] accepted_totals = new int[4];
int eng_count = 0;
int bus_count = 0;
int law_count = 0;
int total = 0;
for(int student = 0; student < school_list.length; student++) {
if(school_list[student][1] == "School of Engineering") {
eng_count += 1;
total += 1;
}
else if(school_list[student][1] == "School of Business") {
bus_count += 1;
total += 1;
}
else if(school_list[student][1] == "Law School") {
law_count += 1;
total += 1;
}
}
accepted_totals[0] = eng_count;
accepted_totals[1] = bus_count;
accepted_totals[2] = law_count;
accepted_totals[3] = total;
return accepted_totals;
}
public static void acceptanceReport(int[] accepted_list) {
String[] school_names = {"School of Engineering", "School of Business", "Law School", "Total Accepted"};
System.out.println("Report on the number of students accepted to each school: ");
for(int school = 0; school < 4; school++) {
System.out.println(school_names[school] + ": " + accepted_list[school]);
}
}
public static void notAccepted(String[][] school_list) {
System.out.println("Number of students not accepted into Humber: ");
int num_students = 0;
for(int student = 0; student < school_list.length; student++) {
if(school_list[student][1] == "Not accepted") {
num_students += 1;
}
}
System.out.println(num_students);
}
public static void schoolReport(String[][] school_list) {
System.out.println("Student acceptance report:");
for(int student = 0; student < school_list.length; student++) {
System.out.println(school_list[student][0] + "'s eligibility: " + school_list[student][1]);
}
}
public static void highestGpaSchool(String[][] school_list, int[][] gpa_list){
System.out.println("Report on students with the highest GPA per school: ");
int eng_max = 0;
String eng_name = "No one";
int bus_max = 0;
String bus_name= "No one";
int law_max = 0;
String law_name = "No one";
int not_max = 0;
String not_name = "No one";
for(int student = 0; student < school_list.length; student++) {
if(school_list[student][1] == "School of Engineering" && gpa_list[student][1] > eng_max) {
eng_max = gpa_list[student][1];
eng_name = school_list[student][0];
}
else if (school_list[student][1] == "School of Business" && gpa_list[student][1] > bus_max) {
bus_max = gpa_list[student][1];
bus_name = school_list[student][0];
}
else if (school_list[student][1] == "Law School" && gpa_list[student][1] > law_max) {
law_max = gpa_list[student][1];
law_name = school_list[student][0];
}
else if (school_list[student][1] == "Not accepted" && gpa_list[student][1] > not_max) {
not_max = gpa_list[student][1];
not_name = school_list[student][0];
}
}
}
}