-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourse2.java
More file actions
41 lines (34 loc) · 1.1 KB
/
Course2.java
File metadata and controls
41 lines (34 loc) · 1.1 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
public class Course2 implements Cloneable {
private String courseName;
private String[] students = new String[100];
private int numberOfStudents;
public Course2(String courseName) {
this.courseName = courseName;
}
public void addStudent(String student) {
students[numberOfStudents] = student;
numberOfStudents++;
}
public String[] getStudents() {
return students;
}
public int getNumberOfStudents() {
return numberOfStudents;
}
public String getCourseName() {
return courseName;
}
public void dropStudent(String student) {
// Additional code for dropping a student will be needed here
}
@Override
protected Object clone() throws CloneNotSupportedException {
Course cloned = (Course) super.clone(); // Clone the Course object
cloned.students = new String[students.length]; // Create a new students array
// Copy each student
for (int i = 0; i < numberOfStudents; i++) {
cloned.students[i] = new String(students[i]);
}
return cloned;
}
}