Student class exercice

Student exercice for Tuesday, November 12th

Write a class for students, and a class to test it.

Each student should have a name, a mark and an id number. All id numbers should be different. Write a constructor and accessors. Write a mutator to set the student's mark. Write a method that tells if the student passed or not with respect to a passing grade that should be a constant of your Student class.

Correction:
/** A <code>Student</code> has a name, a mark and a student id. */
class Student{
    private String name;
    private int mark;
    private int idNumber;
    
    private static int nextIdNumber=1; //To record the id number that will be given to the next constructed student.
    
    /**This is a constant for the university required passing mark.*/
    public static final int PASSING_MARK=60; //it needs not be private as it is not secrete, and final variables cannot be modified.
    
    /**To create a <code>Student</code> we have to know his name. The id number is
    automatically set.
    */
    public Student(String aName){
        name=aName;
        idNumber=nextIdNumber;
        nextIdNumber++;
    }
    
    /**Mutator to set the mark.*/
    public void setMark(int aMark){
        mark=aMark;
    }
    
    /**Accessor to the name.*/
    public String getName(){
        return name;
    }
    
    /**Accessor to the mark.*/
    public int getMark(){
        return mark;
    }
    
    /**Accessor to the id number.*/
    public int getIdNumber(){
        return idNumber;
    }
    
    /**Accessor to the static field that stores the next id number.*/
    public static int getNextIdNumber(){
        return nextIdNumber;
    }
    
    /**To check if a student is passing or not.*/
    public boolean isPassing(){
        return (mark>=PASSING_MARK);
    }
}

class StudentTest{

    public static void main(String[] args){
        Student dalia=new Student("Dalia Roshdy al-Aloul");
        dalia.setMark(90); //I hope so...
        System.out.println(dalia.getName()+" ("+dalia.getIdNumber()+")");
        if (dalia.isPassing()) System.out.println("Mabrouk");
    }
}