package package10;
public class Course {
private String courseName;
private String[] students = new String [100];
private int numberOfStudents;
public Course(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) {
int index= findStudent(student);
if(index >= 0) {
dropStudent(index);
}
else {
System.out.println(student + "is not in the course:"+
courseName);
}
}
private void dropStudent(int index) {
String[] s= new String[students.length-1];
for(int i=0, j=0; i < s.length; i++,j++) {
if (i==index) {
j++;
}
s[i]=students[j];
}
this.students=s;
numberOfStudents--;
}
private int findStudent(String student) {
for(int i=0;i<numberOfStudents;i++)
{
if(students[i].equals(student)) {
file:///C|/Users/Dell/Desktop/java/Course.txt[3/10/2024 3:57:18 pm]
return i;
}
}
return -1;
}
}
file:///C|/Users/Dell/Desktop/java/Course.txt[3/10/2024 3:57:18 pm]