-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse.java
More file actions
40 lines (31 loc) · 1.04 KB
/
Copy pathCourse.java
File metadata and controls
40 lines (31 loc) · 1.04 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
public class Course {
static int maxCapacity = 100;
String courseName;
int enrollments;
String[] enrolledStudents;
Course(String courseName) {
this.courseName = courseName;
this.enrollments = 0;
this.enrolledStudents = new String[maxCapacity];
}
static void setMaxCapacity(int maxCapacity) {
Course.maxCapacity = maxCapacity;
}
void enrollStudents(String studentName) {
enrolledStudents[enrollments] = studentName;
enrollments++;
}
void unenrollStudents(String studentName) {
System.out.println("Student removed");
enrollments--;
}
public static void main(String[] args) {
// Create a Course object
Course javaCourse = new Course("Java Programming");
// Enroll students
javaCourse.enrollStudents("Alice");
javaCourse.enrollStudents("Bob");
// Print confirmation
System.out.println("Students enrolled in " + javaCourse.courseName + ": " + javaCourse.enrollments);
}
}