从课程中删除学生

时间:2017-06-16 23:42:40

标签: java arrays methods

如何使用下面的drop方法从课程中删除学生?我尝试访问滚动书的课程参数。 但我不知道如何从卷册中删除学生ID。

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();
        }
    }
}

1 个答案:

答案 0 :(得分:-1)

如果您使用数组列表并在每次输入数据时传递新对象,您可以遍历删除功能上的arraylist并执行类似

的操作

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