-
Notifications
You must be signed in to change notification settings - Fork 0
/
Department.java
121 lines (102 loc) · 4.02 KB
/
Department.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
import java.util.Scanner;
public class Department {
Scanner scanner = new Scanner(System.in);
private int departmentNum;
private String departmentName;
private Course[] courses;
private Lecturer[] lecturers;
public Department(int headSubjectNum, String headSubjectName, Course[] courses, Lecturer[] lecturers) {
this.departmentNum = headSubjectNum;
this.departmentName = headSubjectName;
this.courses = courses;
this.lecturers = lecturers;
}
public Course[] getCourses() {
return this.courses;
}
public String getDepartmentName() {
return this.departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public void print() {
System.out.println("Department number: " + this.departmentNum);
System.out.println("Department name: " + this.departmentName);
System.out.println("Department lecturer(s): ");
for (int i = 0; i < this.lecturers.length; i++) {
if (lecturers[i] != null) {
System.out.println((i + 1) + ".");
this.lecturers[i].print();
}
}
System.out.println();
System.out.println("Department course(s): ");
for (int i = 0; i < this.courses.length; i++) {
if (courses[i] != null) {
System.out.println((i + 1) + ".");
this.courses[i].printCourseData();
}
}
}
public void addLecturer() {
System.out.println("Enter the lecturer's first name: ");
String lecturerFName = scanner.nextLine();
System.out.println("Enter the lecturer's last name: ");
String lecturerLName = scanner.nextLine();
System.out.println("Enter the lecturer's years of experience: ");
int lecturerYOE = scanner.nextInt();
boolean isDone = false;
for (int i = 0; i < lecturers.length; i++) {
if (lecturers[i] == null) {
lecturers[i] = new Lecturer(lecturerFName, lecturerLName, lecturerYOE);
isDone = true;
break;
}
}
if (!isDone) {
System.out.println("No room for lecturers.");
} else {
System.out.println("New lecturer added succesfully.");
}
}
public void addCourse() {
System.out.println("Choose a lecturer for the course: ");
if (lecturers[0] != null && lecturers[1] == null) {
// there is only one lecturer
System.out.println("Enter a course name: ");
System.out.print("-> ");
String courseName = scanner.next();
for (int j = 0; j < courses.length; j++) {
if (courses[j] == null) {
courses[j] = new Course(courseName, this.lecturers[0]);
break;
}
}
System.out.println("Course added successfully.");
} else if ((lecturers[0] != null) && (lecturers[1] != null)) {
// there are a few lecturers
System.out.println("Enter a course name: ");
System.out.print("-> ");
String courseName2 = scanner.next();
System.out.println("Choose a lecturer: ");
for (int i = 0; i < lecturers.length; i++) {
if (lecturers[i] != null) {
System.out.println((i + 1) + ". " +
lecturers[i].getFirstName() + " " + lecturers[i].getLastName());
}
}
int lectNum = scanner.nextInt();
for (int j = 0; j < courses.length; j++) {
if (courses[j] == null) {
courses[j] = new Course(courseName2, lecturers[lectNum - 1]);
break;
}
}
System.out.println("Course added successfully.");
} else {
// there are no lecturers
System.out.println("Can not open course! no lecturers available.");
}
}
}