Nur_Mohammed_Mehedy

Course JAVA

Sep 24th, 2021
877
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. public class Course {
  3.  
  4.     private String courseName;
  5.     private String[] students;
  6.     private int numberOfStudents;
  7.    
  8.     public Course(String name) {
  9.         courseName = name;
  10.         numberOfStudents = 0;
  11.         students = new String[100]; // Assuming maximum students = 100
  12.     }
  13.    
  14.     public String getCourseName()
  15.     {
  16.         return courseName;
  17.     }
  18.    
  19.     public void addStudent(String student)
  20.     {
  21.         students[numberOfStudents] = student;
  22.         ++numberOfStudents;
  23.     }
  24.  
  25.     public void dropStudent(String student)
  26.     {
  27.         for(int i=0;i<numberOfStudents;i++)
  28.         {
  29.             if(students[i].equals(student))
  30.             {
  31.                 for(int j=i+1;j<numberOfStudents;j++)
  32.                 {
  33.                     students[j-1] = students[j];
  34.                 }
  35.                 break;
  36.             }
  37.         }
  38.         --numberOfStudents;
  39.     }
  40.    
  41.     public String[] getStudents()
  42.     {
  43.         return students;
  44.     }
  45.    
  46.     public int NumberOfStudents()
  47.     {
  48.         return numberOfStudents;
  49.     }
  50. }
  51.  
RAW Paste Data