-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
945 lines (826 loc) · 35.7 KB
/
Main.java
File metadata and controls
945 lines (826 loc) · 35.7 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
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
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static Scanner input = new Scanner(System.in);
public static final Admin admin = new Admin();
public static Admin newAdmin = new Admin();
public static Student newStd = new Student();
public static void x() {
Scanner input = new Scanner(System.in);
input.nextLine();
}
public static void main(String[] args) {
admin.students = new Student[10];
admin.students[0] = new Student("Haya Abusaq", "2230005103", "Hello.123", 'F', 19, "General");
admin.students[1] = new Student("Fatima faiz", "2230009999", "Ramp00.", 'F', 21, "CIS");
admin.students[2] = new Student("Mariam Barakat", "2230006666", "Amica_1", 'F', 20, "CYS");
admin.students[3] = new Student("Amal Ahmed Al-Khaldi", "2230004318", "Amamal_2h", 'F', 19, "CS");
admin.students[4] = new Student("Mohammed Saad Dari", "2230004319", "mohammed_1Sa", 'M', 21, "CYS");
admin.students[5] = new Student("Lina Yusif Al-Shamrani", "2230004310", "LOoo50_50", 'F', 20, "CYS");
admin.students[6] = new Student("Rayan Ali Baridwan", "2230004311", "Bari15al.i", 'M', 20, "CS");
admin.students[7] = new Student("Sara Omar Al-Shimmiry", "2230004312", "s3_riomar", 'F', 23, "General");
admin.students[8] = new Student("Abdulrahman Yaser Mosa", "2230004313", "MOSA12.mo", 'M', 19, "CIS");
admin.students[9] = new Student("Maria Nasir Al-Qahtani", "2230004314", "maria_N4sir", 'F', 20, "AI");
Course course = new Course();
course.course[0] = new Course("Physics", "PHY101", 3, true, "Fall");
course.course[1] = new Course("Electronics", "ELE201", 3, false, "Spring");
course.course[2] = new Course("Digital Systems", "DIG301", 3, false, "Fall");
course.course[3] = new Course("Introduction to Programming", "CS101", 4, true, "Fall");
course.course[4] = new Course("Data Structures", "CS201", 4, false, "Spring");
course.course[5] = new Course("Algorithms", "CS301", 4, false, "Fall");
for (int i = 0; i < 6; i++) {
Admin.allCourses.add(course.course[i]);
}
Admin.allCourses.get(1).setPrerequisites(new Course[] { Admin.allCourses.get(0) }); // Electronics prerequisites
// Physics
Admin.allCourses.get(2).setPrerequisites(new Course[] { Admin.allCourses.get(1) }); // Digital Systems
// prerequisites Electronics
Admin.allCourses.get(4).setPrerequisites(new Course[] { Admin.allCourses.get(3) }); // Data Structures
// prerequisites
// Introduction to
// Programming
Admin.allCourses.get(5).setPrerequisites(new Course[] { Admin.allCourses.get(4) }); // Algorithms prerequisites
// Data Structures
while (true) {
System.out.println("\n[ Welcome to our System ]");
System.out.println("--------------------");
System.out.println("1.[ Admin System ]");
System.out.println("2.[ Student System ]");
System.out.println("3.[ Exit ]");
System.out.println("--------------------");
System.out.print("--- Your Choice ---> ");
int choice = input.nextInt();
switch (choice) {
case 1:
adminSystem();
break;
case 2:
if (admin.getDoneEditing()) {
studentSystem();
} else {
System.out.println("The system is currently closed for students. Please try again later.");
}
break;
case 3:
System.out.println("Exiting the system. Goodbye <3");
return;
default:
System.out.println("( Invalid choice. Please try again )");
}
}
}
static void adminSystem() {
boolean check = false;
while (!check) {
System.out.println("\n [ Admin System ]");
System.out.println("--------------------------");
System.out.println("1.[ verify access ]");
System.out.println("2.[ Exit ]");
System.out.println("--------------------------");
System.out.print("--- Your Choice ---> ");
int choice = input.nextInt();
input.nextLine();
switch (choice) {
case 1:
System.out.print("Enter Username: ");
String username = input.next();
System.out.print("Enter Password: ");
String password = input.next();
System.out.print("Enter ID : ");
String ID = input.next();
if (!admin.checkAccess(admin, newAdmin, username, password, ID)) {
System.out.println("Invalid [ username ] or [ password ] or [ ID ]");
} else {
System.out.println("\nSuccessful Login!");
adminMenu();
check = true;
}
break;
case 2:
System.out.println("[ Exiting Admin System ]");
check = true;
break;
default:
System.out.println("( Invalid choice. Please try again )");
}
}
}
static void adminMenu() {
while (true) {
System.out.println("\n------------------------");
System.out.println("1.[ Add New Course ]");
System.out.println("2.[ Remove Course ]");
System.out.println("3.[ Display All Students ]");
System.out.println("4.[ Find student by ID ]");
System.out.println("5.[ Display All Courses ]");
System.out.println("6.[ Open the system for Students ]");
System.out.println("7.[ Exit Admin System ]");
System.out.println("------------------------");
System.out.print("--- Your Choice ---> ");
int adminChoice = input.nextInt();
input.nextLine();
switch (adminChoice) {
case 1:
admin.addCourse();
break;
case 2:
if (Admin.allCourses.isEmpty()) {
System.out.println("No courses available.");
break;
}
System.out.print("[ Enter course code to remove ] ---> ");
String courseCode = input.nextLine();
Course courseToRemove = findCourseByCode(courseCode);
if (courseToRemove != null) {
admin.deleteCourse(courseToRemove);
} else {
System.out.println("( Course not found )");
}
break;
case 3:
admin.displayAllStudents();
break;
case 4:
System.out.print("[ Enter student ID to find ] ---> ");
String studentId = input.nextLine();
admin.findStudentByID(studentId);
break;
case 5:
Course course = new Course();
course.displayAllCourses();
break;
case 6:
admin.setDoneEditing(true);
System.out.println("System is now open for students.");
case 7:
System.out.println("Exiting Admin System...");
return;
default:
System.out.println("( Invalid choice. Please try again )");
}
}
}
static void studentSystem() {
Student student = new Student();
boolean found = false;
while (!found) {
System.out.println("\n[ Student System ]");
System.out.println("-----------------------------");
System.out.println("[ Enter your information ]");
System.out.print("Enter ID: ");
String ID = input.next();
System.out.print("Enter Password: ");
String password = input.next();
if (!newStd.checkAccess(admin, newStd, "", password, ID)) {
System.out.println("Invalid [ username ] or [ password ] or [ ID ]");
System.out.println("Please try again");
continue;
} else
break;
}
System.out.println("\nSuccessful Login!");
while (true) {
System.out.println("-----------------------------");
System.out.println("1.[ Add Course to Cart ]");
System.out.println("2.[ Remove Course from Cart ]");
System.out.println("3.[ Display all courses ]");
System.out.println("4.[ Display Course Cart ]");
System.out.println("5.[ Finalize Registration ]");
System.out.println("6.[ Exit Student System ]");
System.out.println("-----------------------------");
System.out.print("--- Your Choice ---> ");
int choice = input.nextInt();
if (!student.finalized || choice == 5 || choice == 6) {
switch (choice) {
case 1:
if (student.courseCart.size() < Student.MAX_COURSES_NUMBER) {
System.out.print("[ Enter course code to add ] ---> ");
String addedCourseCode = input.next();
Course addedCourse = findCourseByCode(addedCourseCode);
if (addedCourse != null) {
student.addCourseToCart(addedCourse);
} else {
System.out.println("( Course not found )");
}
break;
} else {
System.out.println("You have reached the maximum number of courses in the cart.");
break;
}
case 2:
if (student.courseCart.size() == 0) {
System.out.println("No courses in the cart.");
break;
}
System.out.print("[ Enter course code to remove ] ---> ");
String courseCodeToRemove = input.next();
Course courseToRemove = findCourseByCode(courseCodeToRemove);
if (courseToRemove != null) {
student.removeCourseFromCart(courseToRemove);
} else {
System.out.println("( Course not found )");
}
break;
case 3:
Course course = new Course();
course.displayAllCourses();
break;
case 4:
if (student.courseCart.size() == 0) {
System.out.println("No courses in the cart.");
break;
}
student.displayCourseCart();
break;
case 5:
student.finalized = student.finalizeRegistration();
break;
case 6:
System.out.println("[ Exiting Student System <3]");
return;
default:
System.out.println("( Invalid choice. Please try again )");
}
} else {
System.out.println("You have already finalized your registration.");
System.out.println("Further changes are not allowed.");
break;
}
}
}
// ... other code ...
static Course findCourseByCode(String courseCode) {
for (Course course : Admin.allCourses) {
if (course != null && course.getCode().equals(courseCode)) {
System.out.println("Course found.");
return course;
}
}
System.out.println("Course is not available currently.");
return null;
}
}
class User {
// Variables that is used for users and will be handed down to the admin&
// students classes
public String name;
public String ID;
private String password;
private char gender;
private int age;
// User default Constructor
User() {
}
// This is User parametrized Constructor
public User(String name, String ID, String password, char gender, int age) {
this.name = name;
this.ID = ID;
this.password = password;
this.gender = gender;
this.age = age;
}
// Getters and Setters for the private variables (Name, password, Age)
public String getPassword() {
return password;
}
public int getAge() {
return age;
}
public void setAge(int age) {
if (age >= 17) {
this.age = age;
} else {
System.out.println("[ Invalid age, try again ]");
setAge(age);
}
}
public char getGender() {
return gender;
}
public void setGender(char gender) {
this.gender = gender;
}
// Method to check if the user is allowed to enter
public boolean checkAccess(Admin admin, User user, String userName, String userPassword, String userID) {
System.out.println("Checking access...");
if (user instanceof Admin) {
// check if the user is an admin to confirm his specified identity
System.out.println("Admin detected...");
if (userID.equals("z") && userName.equalsIgnoreCase("z") && userPassword.equals("z")) {
// if (userID.equals("111000123") && userName.equalsIgnoreCase("Fatimah") &&
// userPassword.equals("Fa.1234")) {
System.out.println("Admin access granted.");
return true;
} else {
System.out.println("Admin access denied.");
return false;
}
} else {
System.out.println("Student detected...");
// if the user is a student check the account within the array of students
// using name, password ID
for (int i = 0; i < Student.totalOfStd; i++) {
if (userID.equals(admin.students[i].ID) && userPassword.equals(admin.students[i].getPassword())) {
System.out.println("Student access granted.");
user = admin.students[i];
return true;
}
}
System.out.println("Student access denied.");
return false; // return false if the guest is not found across the array
}
}
}
class Admin extends User {
public static ArrayList<Course> allCourses = new ArrayList<Course>();
public Student[] students;
private boolean doneEditing;
// Default constructor for Admin
Admin() {
}
Admin(String name, String ID, String password, char gender, int age, boolean doneEditing) {
this.name = "Fatimah";
this.ID = "2230005100";
password = "Fa.1234";
}
public boolean getDoneEditing() {
return doneEditing;
}
public void setDoneEditing(boolean doneEditing) {
this.doneEditing = doneEditing;
}
public void displayAllStudents() { // Display the information of all students
System.out.println(" [ Total of students ] : " + Student.totalOfStd);
for (int i = 0; i < Student.totalOfStd; i++) {
System.out.println("---> Student #" + (i + 1) + " :");
students[i].displayStudentInfo(); // Display the information of each student
System.out.println("\n----------------------------");
}
}
public void findStudentByID(String studentID) {// Find a student by their ID
boolean found = false;
for (int i = 0; i < Student.totalOfStd; i++) {
if (students[i].ID.equals(studentID)) {// 2- If the student ID matches, display the student's information
found = true;
students[i].displayStudentInfo();
System.out.println("[ Student's registration status ] : " + students[i].finalized);
System.out.println("----------------------------------------");
}
}
if (!found)
System.out.println("[ A student with ID # ] ---- " + studentID + "[ does not exist ]");
// 3- If the student ID doesn't match, display an error message
}
public void addCourse() { // Add a new course to the system
Scanner input = new Scanner(System.in);
System.out.print("[ Enter the new course's code ] ---> ");
String code = input.next();
for (Course course : allCourses) {
if (course.getCode().equals(code)) {
System.out.println("( --- This course already exists --- )");
return;
}
}
Course newCourse = new Course();
newCourse.setCode(code);
System.out.println("[ Enter the new course's information ]");
System.out.print(" [Name] --> ");
Main.x();
newCourse.setName(input.nextLine());
System.out.print(" [Credits] --> ");
newCourse.setCredit(input.nextInt());
boolean isGeneral;
do {
System.out.print("[ Is it a General Course ] ? [ Enter true or false ] ---> ");
isGeneral = input.nextBoolean();
} while (isGeneral != true && isGeneral != false);
newCourse.setGeneralCourse(isGeneral);
newCourse.setSemesterOffered();
String hasPrereqs;
do {
System.out.print("[ Does this course have prerequisites ] ? [ Enter yes or no ] ---> ");
hasPrereqs = input.next();
} while (!hasPrereqs.equals("yes") && !hasPrereqs.equals("no"));
if (hasPrereqs.equals("yes")) {
System.out.print("[ Enter the number of prerequisites ] ---> ");
int numPrereqs = input.nextInt();
Course[] prerequisites = new Course[numPrereqs];
for (int i = 0; i < numPrereqs; i++) {
System.out.print("Enter the code of prerequisite #" + (i + 1) + ": ");
String prereqCode = input.next();
boolean found = false;
for (Course course : allCourses) {
if (course.getCode().equals(prereqCode)) {
prerequisites[i] = course;
found = true;
break;
}
}
if (!found) {
System.out.println("[ Prerequisite course with code ] " + prereqCode + "[ not found ]");
prerequisites[i] = null;
}
}
newCourse.setPrerequisites(prerequisites);
} else {
newCourse.setPrerequisites(new Course[0]);
allCourses.add(newCourse);
System.out.println("[ Course added successfully! ]");
}
}
public void deleteCourse(Course course) {
if (allCourses.remove(course)) {
System.out.println("The course [" + course.getCode() + "] deleted.");
} else {
System.out.println("Course not found.");
}
}
}
class Student extends User {
public boolean finalized = false;
public static final int MAX_COURSES_NUMBER = 7;
public static final int MAX_HOURS_NUMBER = 17;
public static final int MIN_HOURS_NUMBER = 13;
public ArrayList<Course> courseCart;
private String major;
public static final int totalOfStd = 10;
// Default constructor for student
Student() {
this.courseCart = new ArrayList<>(MAX_COURSES_NUMBER);
}
// Parametrized Constructor for student
public Student(String name, String ID, String password, char gender, int age, String major) {
super(name, ID, password, gender, age);
this.major = major;
this.courseCart = new ArrayList<>(MAX_COURSES_NUMBER);
}
// Getter and Setter for Major
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public void displayStudentInfo() { // Display the student's information
System.out.println("Student's name: " + name);
System.out.println("ID: " + ID);
System.out.println("Gender: " + getGender());
System.out.println("Age: " + getAge());
System.out.println("Major: " + major);
System.out.println("Credit hours: " + calcCreditHours());
}
// Add course to cart
public void addCourseToCart(Course course) {
if (courseCart.contains(course)) {
System.out.println("Course already in cart.");
return;
}
if (courseCart.size() < MAX_COURSES_NUMBER) {
courseCart.add(course);
System.out.println("Course added to cart.");
} else {
System.out.println("Cannot add more courses. Cart is full.");
}
}
// Remove course from cart
public void removeCourseFromCart(Course course) {
if (courseCart.remove(course)) {
System.out.println("Course removed from cart.");
} else {
System.out.println("Course not found in cart.");
}
}
// Display course cart
public void displayCourseCart() {
if (courseCart.isEmpty()) {
System.out.println("No courses in the cart.");
} else {
System.out.println("Courses in the cart:");
for (Course course : courseCart) {
course.displayCourseInfo();
}
}
}
// Finalize registration
public boolean finalizeRegistration() {
int creditHours = calcCreditHours();
System.out.println("Current credit hours: " + creditHours);
if (creditHours < MIN_HOURS_NUMBER) {
System.out.println("You must register for at least 13 credit hours.");
return false;
} else if (creditHours > MAX_HOURS_NUMBER) {
System.out.println("You cannot register for more than 17 credit hours.");
return false;
} else {
System.out.println("Registration finalized successfully.");
return true;
}
}
public int calcCreditHours() { // Calculate the total credit hours of the student
int totalCreditHours = 0;
for (Course course : courseCart) {
totalCreditHours += course.getCredit();
}
return totalCreditHours;
}
}
class FeeCalculation extends Student {
// Constants defining the components of the registration fee
private static final int JOINING_FEE = 15000; // Joining fee charged once during registration
private static final int FEE_PER_HOUR = 2000; // Fee per credit hour of the course
private static final double TAX_RATE = 0.15; // Tax rate (15%) to be applied to the total fee
private static final double DISCOUNT_RATE = 0.20; // Discount rate (20%)
// New properties to determine eligibility for a discount
private boolean hasDisability; // If the student has a disability
private boolean isHighAchiever; // If the student has a high school percentage above 97%
private boolean isEmployee; // If the student is an employee
/**
* Constructor for FeeCalculation class.
* This constructor initializes the student object with details inherited from
* the Student class.
*/
public FeeCalculation(String name, String ID, String password, char gender, int age, String major,
Course[] courseCart, boolean hasDisability, boolean isHighAchiever, boolean isEmployee) {
super(name, ID, password, gender, age, major);
this.hasDisability = hasDisability;
this.isHighAchiever = isHighAchiever;
this.isEmployee = isEmployee;
}
/**
* Method to calculate the total registration fee, including the joining fee,
* course fees based on the number of credit hours, tax, and applying any
* applicable discount.
*/
public void calculateRegistrationFee() {
int totalCourseHours = 0;
// Loop through the student's course cart to calculate the total number of
// credit hours
for (Course course : courseCart) {
totalCourseHours += course.getCredit(); // Add the credit hours of each course
}
// Calculate the total course fee by multiplying the total credit hours by the
// fee per hour
int totalCourseFee = totalCourseHours * FEE_PER_HOUR;
// Calculate the total fee before tax by adding the joining fee and the total
// course fee
double totalFeeBeforeTax = JOINING_FEE + totalCourseFee;
// Calculate the tax amount based on the total fee before tax
double taxAmount = totalFeeBeforeTax * TAX_RATE;
// Calculate the total fee including the tax
double totalFeeWithTax = totalFeeBeforeTax + taxAmount;
// Now apply the discount (20%) on the total fee after tax, if eligible
double finalFee = totalFeeWithTax;
boolean discountApplied = false;
if (isEligibleForDiscount()) {
finalFee = totalFeeWithTax * (1 - DISCOUNT_RATE); // Apply 20% discount after tax
discountApplied = true;
}
// Print the breakdown of the total fee
System.out.println("Joining Fee: " + JOINING_FEE + " SAR");
System.out.println("Course Fee (" + totalCourseHours + " hours): " + totalCourseFee + " SAR");
System.out.println("Tax (15%): " + taxAmount + " SAR");
// If a discount was applied, show the discount and final price
if (discountApplied) {
System.out.println("Congratulations! You are eligible for a 20% discount.");
System.out.println("Discount (20%): -" + (totalFeeWithTax - finalFee) + " SAR");
}
System.out.println("Total Fee after discount: " + finalFee + " SAR");
}
/**
* Method to check if the student is eligible for a discount.
* The student is eligible if they have a disability, a high achiever (above
* 97%), or an employee.
*/
private boolean isEligibleForDiscount() {
return hasDisability || isHighAchiever || isEmployee;
}
}
class Department {
private String departmentName;
private String departmentCode;
private String professors;
private Course[] coursesOffersd;
private int courseCount;
// constructor of Department Class
public Department(String departmentName, String departmentCode, int maxCourse) {
this.departmentName = departmentName;
this.departmentCode = departmentCode;
this.professors = "";
this.coursesOffersd = new Course[maxCourse];
this.courseCount = 0;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public String getDepartmentCode() {
return departmentCode;
}
public void setDepartmentCode(String departmentCode) {
this.departmentCode = departmentCode;
}
public String getProfessors() {
return professors;
}
public void setProfessors(String professors) {
this.professors = professors;
}
// Methods
public void addProfessor(String professor) {
this.professors += professor + ":";
}
// public void addCourse(Course course) {
// if (courseCount < coursesOffersd.length) {
// this.coursesOffersd[courseCount] = course;
// courseCount++;
// } else {
// System.out.println("No more space to add new course.");
// }
// }
}
class Instructor extends Department {
private String name;
private String id;
private String officeHours;
// Constructor
public Instructor(String name, String id, String officeHours, String departmentName, String departmentCode,
int maxCourse) {
super(departmentName, departmentCode, maxCourse); // Initialize the parent Department class with departmentName,
// departmentCode, and maxCourse
this.name = name;
this.id = id;
this.officeHours = officeHours;
}
// Getter and Setter for Name
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
// Getter and Setter for ID
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
// Getter and Setter for Office Hours
public String getOfficeHours() {
return officeHours;
}
public void setOfficeHours(String officeHours) {
this.officeHours = officeHours;
}
// Display Instructor Info
public String getInstructorInfo() {
return "Instructor Name: " + name + "\nID: " + id + "\nOffice Hours: " + officeHours + "\nDepartment Code: "
+ getDepartmentCode();
}
// Methods to update Department information
public void changeDepartment(String newDepartmentCode, String newDepartmentName) {
System.out.println("Changing department from " + getDepartmentCode() + " to " + newDepartmentCode);
setDepartmentCode(newDepartmentCode); // Update the parent class's department code
setDepartmentName(newDepartmentName); // Update department name
}
// Assign Office Location
private String officeLocation; // New attribute for office location
public String getOfficeLocation() {
return officeLocation;
}
public void setOfficeLocation(String officeLocation) {
this.officeLocation = officeLocation;
}
// Method to display full instructor profile
public void displayProfile() {
System.out.println("Instructor Profile:");
System.out.println("Name: " + name);
System.out.println("ID: " + id);
System.out.println("Office Hours: " + officeHours);
System.out.println("Office Location: " + (officeLocation != null ? officeLocation : "Not Assigned"));
System.out.println("Department Code: " + getDepartmentCode());
}
}
class Course {
private String name;
private String code;
private int credit;
private boolean isGeneralCourse;
private Course[] prerequisites;
public static final int MAX_COURSES = 30;
Course[] course = new Course[MAX_COURSES];
private String SemesterOffered;
public Course() {
this.name = "";
this.code = "";
this.credit = 0;
this.isGeneralCourse = false;
this.SemesterOffered = "";
this.prerequisites = new Course[0];
}
public Course(String name, String code, int credit, boolean isGeneralCourse, String SemesterOffered) {
this.name = name;
this.code = code;
this.credit = credit;
this.isGeneralCourse = isGeneralCourse;
this.SemesterOffered = SemesterOffered;
this.prerequisites = new Course[0];
Admin.allCourses.add(this);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public int getCredit() {
return credit;
}
public void setCredit(int credit) {
this.credit = credit;
}
public boolean getGeneralCourse() {
return isGeneralCourse;
}
public void setGeneralCourse(boolean isGeneralCourse) {
this.isGeneralCourse = isGeneralCourse;
}
public Course[] getPrerequisites() {
return prerequisites;
}
public void setPrerequisites(Course[] prerequisites) {
this.prerequisites = prerequisites;
}
public String getSemester() {
return SemesterOffered;
}
public void setSemesterOffered() {
System.out.println(" [Choose Semester Offered ]");
Scanner input = new Scanner(System.in);
int choice = 0;
if (isGeneralCourse) {
System.out.println("General courses are offered in all semesters.");
SemesterOffered = "All";
return;
}
while (choice < 1 || choice > 4) {
System.out.println("[ 1.Fall\n2.Spring\n3.Summer\n4.Winter ]");
System.out.print("Enter the semester offered: ");
choice = input.nextInt();
if (choice == 1) {
SemesterOffered = "Fall";
} else if (choice == 2) {
SemesterOffered = "Spring";
} else if (choice == 3) {
SemesterOffered = "Summer";
} else if (choice == 4) {
SemesterOffered = "Winter";
} else {
System.out.println("Invalid input. Please enter a number between 1 and 4.");
}
}
}
public boolean hasPrerequisite(Course course) {
for (Course prereq : prerequisites) {
if (prereq.getCode().equals(course.getCode())) {
return true;
}
}
return false;
}
public void displayCourseInfo() {
System.out.println("Course Name: " + name);
System.out.println("Course Code: " + code);
System.out.println("Credits: " + credit);
System.out.println("General Course: " + (isGeneralCourse ? "Yes" : "No"));
System.out.println("Semester Offered: " + SemesterOffered);
System.out.print("Prerequisites: ");
if (prerequisites.length == 0) {
System.out.println("None");
} else {
for (Course prereq : prerequisites) {
System.out.print(prereq.getName() + " (" + prereq.getCode() + "), ");
}
System.out.println();
}
}
public void displayAllCourses() {
if (Admin.allCourses.isEmpty()) {
System.out.println("No courses available.");
return;
}
System.out.println("All Courses:");
for (Course course : Admin.allCourses) {
course.displayCourseInfo();
System.out.println("---------------");
}
}
}