package studentDB; /** * Represents a student. A student has a name and a student * number. */ public class Student { // The name and student number are represented as // private fields. private String name; private int studentNumber; /** * A student can be created without specifying the * name or student number */ public Student () {} /** * Creates a student with the given name and student number. * @param name The student's name * @param studentNumber The student's student number */ public Student (String name, int studentNumber) { this.name = name; this.studentNumber = studentNumber; } /** * Sets the student's name to the given name. * @param name The student's name */ public void setName (String name) { this.name = name; } /** * Returns the student's name. * @return The student's name */ public String getName () { return name; } /** * Sets the student's student number to the given student number. * @param studentNumber The student's student number */ public void setStudentNumber (int studentNumber) { this.studentNumber = studentNumber; } /** * Returns the student's student number. * @return The student's student number */ public int getStudentNumber () { return studentNumber; } /** * Determines whether this student equals the given student. * Two students are equal if they have the same student number. * @param s The student we are testing for equality * @return Whether this student is equal to the given student */ public boolean equals (Student s) { if (studentNumber == s.getStudentNumber()) { Util.assert (name.equals (s.getName()), "students have same st # but different names"); return true; } else { return false; } } /** * Returns a string representation of the student's * name and student number. */ public String toString () { return ("Name: " + name + "; Student number: " + studentNumber); } }