-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.java
More file actions
57 lines (49 loc) · 1.27 KB
/
Copy pathCourse.java
File metadata and controls
57 lines (49 loc) · 1.27 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
/**
* Course class stores course info and tracks total enrollments.
*/
public class Course {
private String courseCode;
private String name;
private int maxCapacity;
private int currentEnrollment;
private static int totalEnrolledStudents = 0;
public Course(String courseCode, String name, int maxCapacity) {
this.courseCode = courseCode;
this.name = name;
this.maxCapacity = maxCapacity;
this.currentEnrollment = 0;
}
public String getCourseCode() {
return courseCode;
}
public String getName() {
return name;
}
public int getMaxCapacity() {
return maxCapacity;
}
public int getCurrentEnrollment() {
return currentEnrollment;
}
/**
* Checks if course has space available.
*/
public boolean hasSpace() {
return currentEnrollment < maxCapacity;
}
/**
* Enrolls a student in this course.
*/
public void enrollStudent() {
if (hasSpace()) {
currentEnrollment++;
totalEnrolledStudents++;
}
}
/**
* Static method to get total enrolled students across all courses.
*/
public static int getTotalEnrolledStudents() {
return totalEnrolledStudents;
}
}