0% found this document useful (0 votes)
7 views2 pages

Course

Uploaded by

kikimoacc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Course

Uploaded by

kikimoacc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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]

You might also like