-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.java
747 lines (523 loc) · 24.7 KB
/
Menu.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
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
import java.util.Scanner;
import java.io.*;
/*The main method in Java accepts an array of strings (String[] args) as a parameter to allow passing command-line arguments to the program.
* When you run a Java program from the command line,
* you can provide additional arguments separated by spaces,
* and these arguments will be passed to the main method as elements of the args array.
*
*/
public class Menu {
static Scanner scnr = new Scanner(System.in);
private static Object yesOrno;
public static void main(String[] args) {
do {
int num = 0;
Course [] c;
Course course;
System.out.println("**************************************************************");
System.out.println("Entering the school database.........");
System.out.println("**************************************************************");
System.out.println("SCHOOL DATABASE INFO:");
System.out.println();
System.out.println("************************************************");
System.out.println("COURSES:");
System.out.println("How many courses do you want to create?");
num = scnr.nextInt();
System.out.println("Enter "+num+" courses as indicated below:");
c = new Course[num];
for (int i = 0; i < c.length;i++) { // calls the createCourse method while the loop iterates until the array is filled
course = createCourse(); //this allow us to create and assign a object at each index
c[i] = course;
}
for (int i = 0; i < c.length;i++) {
System.out.println(c[i].toString());
}
System.out.println("************************************************");
System.out.println("************************************************");
System.out.println("PERSONS:");
System.out.println("************************************************");
System.out.println("************************************************");
System.out.println("EMPLOYEES:");
System.out.println("************************************************");
System.out.println("************************************************");
System.out.println("GENERAL STAFF:");
// /*
int num2 = 0;
GeneralStaff [] gs;
GeneralStaff staff;
System.out.println("What is the number of Staff?");
num2 = scnr.nextInt();
System.out.println("Enter info for "+num2+" Staff:" );
gs = new GeneralStaff[num2];
for (int i = 0; i < gs.length;i++) { // calls the method while the loop iterates until the array is filled
staff = createGeneralStaff(); //this allow us to create and assign a object at each index
gs[i] = staff;
}
for (int i = 0; i < gs.length;i++) {
System.out.println(gs[i].toString());
}
// */
System.out.println("************************************************");
System.out.println("************************************************");
System.out.println("FACULTY:");
int num3 = 0;
Faculty [] fa;
Faculty faculty;
System.out.println("What is the number of Faculty?");
num3 = scnr.nextInt();
System.out.println("Enter info for "+num3+" Faculty as indicated below:" );
fa = new Faculty[num3];
for (int i = 0; i < fa.length;i++) { // calls the method while the loop iterates until the array is filled
faculty = createFaculty(); //this allow us to create and assign a object at each index
fa[i] = faculty;
}
for (int i = 0; i < fa.length;i++) {
System.out.println(fa[i].toString());
}
System.out.println("Specify the faculty and what courses will they teach as indicated below:");
System.out.println("indicate the faculty by their employee number:");
int employeeNumber = scnr.nextInt();
for (int i = 0; i < fa.length;i++) {
if (fa[i].getEmployeeID() == employeeNumber) {
System.out.println("The faculty chosen is: "+fa[i].toString()+"\n");
System.out.println("Indicate the amount of courses "+fa[i].getName() +" will teach:");
int numCourses = scnr.nextInt();
int tracker = 0;
while(tracker < numCourses ) {
fa[i].addCourseTaught(c[tracker]);
tracker++;
}
System.out.println(numCourses+" courses were added!");
System.out.println(fa[i].toString()+"\n");
System.out.println("Indicate if "+fa[i].getName()+" will be teaching any new courses:");
System.out.println("Enter Yes or No:");
String reply = scnr.next();
if (reply.equalsIgnoreCase("yes") || (reply.equalsIgnoreCase("Yes")) || (reply.equalsIgnoreCase("YES")) ) {
System.out.println("Indicate the number of new courses that "+fa[i].getName()+" will be teaching:");
numCourses = scnr.nextInt();
System.out.println(numCourses +" will be added, specify the courses as indicated below:");
int newLength = c.length + numCourses;
Course [] c2 = new Course[newLength];
for (int j = 0; j < c.length ;j++) { //Assigning old values from old array to new since arrays have a fixed size
c2[j] = c[j];
}
for (int j = c.length; j < c2.length ;j++) { // calls the createCourse method while the loop iterates until the array is filled
course = createCourse(); //we start iterating from the length of the previous array since we just want to add the new courses
c2[j] = course;
fa[i].addCourseTaught(c2[j]); //allows us too keep adding new to the specific faculty object
}
System.out.println(numCourses+" new courses were added!");
System.out.println(fa[i].toString()+"\n");
System.out.println("Indicate if you would be accessing a specific course from "+fa[i].getName()+":");
System.out.println("Enter Yes or No:");
reply = scnr.next();
if (reply.equalsIgnoreCase("yes") || (reply.equalsIgnoreCase("Yes")) || (reply.equalsIgnoreCase("YES")) ) {
System.out.println("Indicate the specific course by the course number:");
int courseNum = scnr.nextInt();
boolean courseFound = false;
for (int j = 0; j < c2.length; j++) {
if (c2[j].getCourseNum() == courseNum) {
System.out.println(fa[i].getCourseTaughtAsString(j));
courseFound = true;
break;
}
}
if (!courseFound) {
System.out.println(fa[i].getName() + " is not teaching this course.");
}
}
else {
System.out.println("No courses will be accessed.");
}
System.out.println("Choose another faculty by their employee number:");
int employee = scnr.nextInt();
for (int j = 0; j < fa.length;j++) {
if (fa[j].getEmployeeID() == employee) {
System.out.println("The faculty chosen is: "+fa[j].toString()+"\n");
System.out.println("Indicate the amount of courses "+fa[j].getName() +" will teach:");
numCourses = scnr.nextInt();
System.out.println(numCourses +" will be added, specify the courses as indicated below:");
newLength = c2.length + numCourses;
Course [] c3 = new Course[newLength];
for (int k = 0; k < c2.length; k++) { //Assigning old values from old array to new since arrays have a fixed size
c3[k] = c2[k];
}
for (int k = c2.length; k < c3.length ;k++) { // calls the createCourse method while the loop iterates until the array is filled
course = createCourse(); //we start iterating from the length of the previous array since we just want to add the new courses
c3[k] = course;
fa[j].addCourseTaught(c3[k]); //allows us too keep adding new to the specific faculty object
}
System.out.println(numCourses+" courses were added!");
System.out.println(fa[j].toString()+"\n");
System.out.println(mostCoursesTaught(fa));
System.out.println(leastCoursesTaught(fa));
System.out.println("The max course number is: "+maxCourseNum(c3));
System.out.println("The min course number is: "+minCourseNum(c3));
courseObjects(c3);
//
}
}
}
else {
System.out.println(fa[i].getName()+" will not be teaching any new courses.");
System.out.println("Indicate if you would be accessing a specific course from "+fa[i].getName()+":");
System.out.println("Enter Yes or No:");
reply = scnr.next();
if (reply.equalsIgnoreCase("yes") || (reply.equalsIgnoreCase("Yes")) || (reply.equalsIgnoreCase("YES")) ) {
System.out.println("Indicate the specific course by the course number:");
int courseNum = scnr.nextInt();
boolean courseFound = false;
for (int j = 0; j < c.length; j++) {
if (c[j].getCourseNum() == courseNum) {
System.out.println(fa[i].getCourseTaughtAsString(j));
courseFound = true;
break;
}
}
if (!courseFound) {
System.out.println(fa[i].getName() + " is not teaching this course.");
}
}
else {
System.out.println("No courses will be accessed.");
}
System.out.println("Choose another faculty by their employee number:");
int employee = scnr.nextInt();
for (int j = 0; j < fa.length;j++) {
if (fa[j].getEmployeeID() == employee) {
System.out.println("The faculty chosen is: "+fa[j].toString()+"\n");
System.out.println("Indicate the amount of courses "+fa[j].getName() +" will teach:");
numCourses = scnr.nextInt();
System.out.println(numCourses +" will be added, specify the courses as indicated below:");
int newLength = c.length + numCourses;
Course [] c3 = new Course[newLength];
for (int k = 0; k < c.length; k++) { //Assigning old values from old array to new since arrays have a fixed size
c3[k] = c[k];
}
for (int k = c.length; k < c3.length ;k++) { // calls the createCourse method while the loop iterates until the array is filled
course = createCourse(); //we start iterating from the length of the previous array since we just want to add the new courses
c3[k] = course;
fa[j].addCourseTaught(c3[k]); //allows us too keep adding new to the specific faculty object
}
System.out.println(numCourses+" courses were added!");
System.out.println(fa[j].toString()+"\n");
System.out.println(mostCoursesTaught(fa));
System.out.println(leastCoursesTaught(fa));
System.out.println("The max course number is: "+maxCourseNum(c3));
System.out.println("The min course number is: "+minCourseNum(c3));
courseObjects(c3);
//
}
}
}
}
}
System.out.println("************************************************");
System.out.println("************************************************");
System.out.println("STUDENTS:");
int num4 = 0;
Student [] st;
Student student;
System.out.println("What is the number of Students?");
num4 = scnr.nextInt();
System.out.println("Enter info for "+num4+" Students as indicated below:" );
st = new Student[num4];
for (int i = 0; i < st.length;i++) { // calls the method while the loop iterates until the array is filled
student = createStudent(); //this allow us to create and assign a object at each index
st[i] = student;
}
for (int i = 0; i < st.length;i++) {
System.out.println(st[i].toString());
}
System.out.println("Specify the student and what courses will they be taking as indicated below:");
System.out.println("indicate the student by their student ID number:");
int studentNumber = scnr.nextInt();
for (int i = 0; i < st.length;i++) {
if (st[i].getStudentID() == studentNumber) {
System.out.println("The student chosen is: "+st[i].toString()+"\n");
System.out.println("Indicate the amount of courses "+st[i].getName() +" will take:");
int numCourses = scnr.nextInt();
int tracker = 0;
while(tracker < numCourses ) {
st[i].addCourseTaken(c[tracker]);
tracker++;
}
System.out.println(numCourses+" courses were added!");
System.out.println(st[i].toString()+"\n");
System.out.println("Indicate if "+st[i].getName()+" will be taking any new courses:");
System.out.println("Enter Yes or No:");
String reply = scnr.next();
if (reply.equalsIgnoreCase("yes") || (reply.equalsIgnoreCase("Yes")) || (reply.equalsIgnoreCase("YES")) ) {
System.out.println("Indicate the number of new courses that "+st[i].getName()+" will be taking:");
numCourses = scnr.nextInt();
System.out.println(numCourses +" will be added, specify the courses as indicated below:");
int newLength = c.length + numCourses;
Course [] c4 = new Course[newLength];
for (int j = 0; j < c.length ;j++) { //Assigning old values from old array to new since arrays have a fixed size
c4[j] = c[j];
}
for (int j = c.length; j < c4.length ;j++) { // calls the createCourse method while the loop iterates until the array is filled
course = createCourse(); //we start iterating from the length of the previous array since we just want to add the new courses
c4[j] = course;
st[i].addCourseTaken(c4[j]); //allows us too keep adding new to the specific faculty object
}
System.out.println(numCourses+" new courses were added!");
System.out.println(st[i].toString()+"\n");
System.out.println("Indicate if you would be accessing a specific course from "+st[i].getName()+":");
System.out.println("Enter Yes or No:");
reply = scnr.next();
if (reply.equalsIgnoreCase("yes") || (reply.equalsIgnoreCase("Yes")) || (reply.equalsIgnoreCase("YES")) ) {
System.out.println("Indicate the specific course by the course number:");
int courseNum = scnr.nextInt();
boolean courseFound = false;
for (int j = 0; j < c4.length; j++) {
if (c4[j].getCourseNum() == courseNum) {
System.out.println(st[i].getCourseTakenAsString(j));
courseFound = true;
break;
}
}
if (!courseFound) {
System.out.println("This course is not available.");
}
}
else {
System.out.println("No courses will be accessed.");
}
System.out.println("Choose another student by their student ID number:");
int studentID = scnr.nextInt();
for (int j = 0; j < st.length;j++) {
if (st[j].getStudentID() == studentID) {
System.out.println("The student chosen is: "+st[j].toString()+"\n");
System.out.println("Indicate the amount of courses "+st[j].getName() +" will be taking:");
numCourses = scnr.nextInt();
System.out.println(numCourses +" will be added, specify the courses as indicated below:");
newLength = c4.length + numCourses;
Course [] c5 = new Course[newLength];
for (int k = 0; k < c4.length; k++) { //Assigning old values from old array to new since arrays have a fixed size
c5[k] = c4[k];
}
for (int k = c4.length; k < c5.length ;k++) { // calls the createCourse method while the loop iterates until the array is filled
course = createCourse(); //we start iterating from the length of the previous array since we just want to add the new courses
c5[k] = course;
st[j].addCourseTaken(c5[k]); //allows us too keep adding new to the specific faculty object
}
System.out.println(numCourses+" courses were added!");
System.out.println(st[j].toString()+"\n");
System.out.println(maxCredit(st,c5));
System.out.println(leastCredit(st,c5));
courseObjects(c5);
allObjects(gs,fa,st);
}
}
}
else {
System.out.println(st[i].getName()+" will not be taking any new courses.");
System.out.println("Indicate if you would be accessing a specific course from "+st[i].getName()+":");
System.out.println("Enter Yes or No:");
reply = scnr.next();
if (reply.equalsIgnoreCase("yes") || (reply.equalsIgnoreCase("Yes")) || (reply.equalsIgnoreCase("YES")) ) {
System.out.println("Indicate the specific course by the course number:");
int courseNum = scnr.nextInt();
boolean courseFound = false;
for (int j = 0; j < c.length; j++) {
if (c[j].getCourseNum() == courseNum) {
System.out.println(st[i].getCourseTakenAsString(j));
courseFound = true;
break;
}
}
if (!courseFound) {
System.out.println("This course is not available.");
}
}
else {
System.out.println("No courses will be accessed.");
}
System.out.println("Choose another student by their student ID number:");
int studentID = scnr.nextInt();
for (int j = 0; j < st.length;j++) {
if (st[j].getStudentID() == studentID) {
System.out.println("The student chosen is: "+st[j].toString()+"\n");
System.out.println("Indicate the amount of courses "+st[j].getName() +" will be taking:");
numCourses = scnr.nextInt();
System.out.println(numCourses +" will be added, specify the courses as indicated below:");
int newLength = c.length + numCourses;
Course [] c5 = new Course[newLength];
for (int k = 0; k < c.length; k++) { //Assigning old values from old array to new since arrays have a fixed size
c5[k] = c[k];
}
for (int k = c.length; k < c5.length ;k++) { // calls the createCourse method while the loop iterates until the array is filled
course = createCourse(); //we start iterating from the length of the previous array since we just want to add the new courses
c5[k] = course;
st[j].addCourseTaken(c5[k]); //allows us too keep adding new to the specific faculty object
}
System.out.println(numCourses+" courses were added!");
System.out.println(st[j].toString()+"\n");
System.out.println(maxCredit(st,c5));
System.out.println(leastCredit(st,c5));
courseObjects(c5);
allObjects(gs,fa,st);
try {
File file = new File ("Output.txt");
FileWriter writer = new FileWriter(file);
System.setOut(new PrintStream(file)); //sets the output stream of the program to write to the file
// Call the method that prints to the console
courseObjects(c5);
allObjects(gs, fa, st);
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));// sets output stream back to the console
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("Error writing file.");
}
}
}
}
}
}
System.out.println("************************************************");
System.out.println("**************************************************************");
System.out.println("Do you want to start over? (Yes/No)");
yesOrno = scnr.next();
if (!yesOrno.equals("Yes") || (!yesOrno.equals("yes"))){
System.out.println("Exiting School Database....");
System.out.println("Exit Successful.");
}
} while (yesOrno.equals("Yes") || (yesOrno.equals("yes")));
}
public static Course createCourse() {
System.out.println("Enter true if the course is graduate otherwise false for undergraduate:");
boolean isGraduateCourse = scnr.nextBoolean();
System.out.println("Enter the coutse number:");
int courseNum = scnr.nextInt();
System.out.println("Enter the coutse department by it's 3 letter acronym:");
String courseDept = scnr.next();
System.out.println("Enter the number of credits:");
int numCredits = scnr.nextInt();
Course course = new Course(isGraduateCourse,courseNum,courseDept,numCredits);
return course;
}
public static GeneralStaff createGeneralStaff() {
System.out.println("Enter the staff's name:");
String name = scnr.next()+scnr.nextLine();
System.out.println("Enter the staff's date of birth:");
int birthYear = scnr.nextInt();
System.out.println("Enter the staff's department name by it's 3 letter acronym:");
String deptName = scnr.next()+scnr.nextLine();// returns the input that was skipped
System.out.println("Enter the staff's duty:");
String duty = scnr.next()+scnr.nextLine();
GeneralStaff staff = new GeneralStaff(name,birthYear,deptName,duty);
return staff;
}
public static Faculty createFaculty() {
System.out.println("Enter the faculty's name:");
String name = scnr.next()+scnr.nextLine();
System.out.println("Enter the faculty's date of birth:");
int birthYear = scnr.nextInt();
System.out.println("Enter the faculty's department name by it's 3 letter acronym:");
String deptName = scnr.next()+scnr.nextLine();// returns the input that was skipped
System.out.println("Enter true if the faculty is tenured otherwise enter false:");
boolean isTenured = scnr.nextBoolean();
Faculty faculty = new Faculty(name,birthYear,deptName,isTenured);
return faculty;
}
public static Student createStudent() {
System.out.println("Enter the students name:");
String name = scnr.next()+scnr.nextLine();
System.out.println("Enter the students date of birth:");
int birthYear = scnr.nextInt();
System.out.println("Enter the students major by it's 3 letter acronym:");
String major = scnr.next()+scnr.nextLine();// returns the input that was skipped
System.out.println("Enter true if the course is graduate otherwise false:");
boolean isGraduate = scnr.nextBoolean();
Student student = new Student(name,birthYear,major,isGraduate);
return student;
}
public static String mostCoursesTaught (Faculty[] fa) {
int courseAmount = fa[0].getNumCoursesTaught();
String name = fa[0].getName();
for (int j = 1; j < fa.length ;j++) {
if (fa[j].getNumCoursesTaught() > courseAmount) {
courseAmount = fa[j].getNumCoursesTaught();
name = fa[j].getName();
}
}
return name+" taught the most courses: " +courseAmount;
}
public static String leastCoursesTaught (Faculty[] fa) {
int courseAmount = fa[0].getNumCoursesTaught();
String name = fa[0].getName();
for (int j = 1; j < fa.length ;j++) {
if (fa[j].getNumCoursesTaught() < courseAmount) {
courseAmount = fa[j].getNumCoursesTaught();
name = fa[j].getName();
}
}
return name+" taught the least courses: " +courseAmount;
}
public static int minCourseNum (Course[] c) {
int courseNum = c[0].getCourseNum();
for (int j = 1; j < c.length ;j++) {
if (c[j].getCourseNum() < courseNum) {
courseNum = c[j].getCourseNum();
}
}
return courseNum;
}
public static int maxCourseNum (Course[] c) {
int courseNum = c[0].getCourseNum();
for (int j = 1; j < c.length ;j++) {
if (c[j].getCourseNum() > courseNum) {
courseNum = c[j].getCourseNum();
}
}
return courseNum;
}
static String maxCredit(Student[] s,Course [] c) {
int courseTaken = s[0].getNumCoursesTaken();
int credits = 0;
String name = s[0].getName();
for (int j = 1; j < s.length ;j++) {
if (s[j].getNumCoursesTaken() > courseTaken) {
courseTaken = s[j].getNumCoursesTaken();
name = s[j].getName();
}
}
for (int k = 0; k < courseTaken; k++) {
credits += c[k].getNumCredits();
}
return name+" took the most credits: "+credits+" which = "+courseTaken +" courses taken.";
}
public static String leastCredit(Student[] s, Course[] c) {
int courseTaken = s[0].getNumCoursesTaken();
int credits = 0;
String name = s[0].getName();
for (int j = 1; j < s.length ;j++) {
if (s[j].getNumCoursesTaken() < courseTaken) {
courseTaken = s[j].getNumCoursesTaken();
name = s[j].getName();
}
}
for (int k = 0; k < courseTaken; k++) {
credits += c[k].getNumCredits();
}
return name+" took the least credits: "+credits+" which = "+courseTaken +" courses taken.";
}
public static void courseObjects(Course [] c ) {
for (int i = 0; i < c.length;i++) {
System.out.println(c[i].toString());
}
}
public static void allObjects( GeneralStaff [] gs, Faculty [] fa, Student [] st) {
for ( int k = 0; k < gs.length;k++) {
System.out.println(gs[k].toString());
}
for ( int j = 0; j < fa.length;j++) {
System.out.println(fa[j].toString());
}
for ( int m = 0; m < st.length;m++) {
System.out.println(st[m].toString());
}
}
}