-1

How can I remove a student from the course by using the drop method down below? I tried by accessing the roll book for the course parameter. But I do not how to remove the student id from the roll book.

public static class Student {

    private int studentID;
    private String first;
    private String last;
    private int credits;
    private boolean graduate;

    public Student(int id, String first, String last, boolean graduate) {
        this.studentID = id;
        this.first = first;
        this.last = last;
        this.graduate = graduate;
    }

    public int getID() { return studentID; }

    public String getFirstName() { return first; }

    public String getLastName() { return last; }

    public int getCredits() { return credits; }

    public boolean isGraduate() { return graduate; }

    public void setCredits(int credits) { this.credits = credits; }

    public String toString() { return "[" + studentID + "] " + first + " " + last; }

    public boolean isEnrolled(Course c) {
        return (c.findRollBookEntry(this.getID()) != null);
    }

    public void drop(Course c) {

        for(int i = 0; i<c.getRollBook().length; i++){
            c.findRollBookEntry(i).getStudent();
        }
    }
}
Iofacture
  • 655
  • 3
  • 13
  • 39
  • This should probably be a method on `Course` or `RollBook` (whose source we'd need to see). – Thilo Jun 16 '17 at 23:52
  • 2
    My best guess would be pointing you to [How do I remove objects from an array in Java?](https://stackoverflow.com/questions/112503/how-do-i-remove-objects-from-an-array-in-java), although you really need to post a [mcve], because the code you gave really doesn't give enough details to answer this. – Bernhard Barker Jun 16 '17 at 23:52

1 Answers1

-1

If you are using an array list and passing new objects each time a data is entered you can iterate through the arraylist on the delete function and do something like

If(i.getID()==id_entered) {i.remove();}

  • 1
    Please read [How do I write a good answer?](http://stackoverflow.com/help/how-to-answer) before attempting to answer more questions. This is not an answer, this is a question asking for more information, and should be a comment! –  Jun 16 '17 at 23:55
  • This is not an answer. Do not post a comment as an answer just because you have no rep points. Earn the rep points before you comment. – Hack-R Jun 16 '17 at 23:57
  • Edited my answer to possible solution – Wali Muhammad Khubaib Jun 17 '17 at 00:11