/** * A record for a student in a particular class. * * @author Samuel A. Rebelsky * @version 1.0 of January 1999 */ public class Student { // +--------+-------------------------------------------------- // | Fields | // +--------+ /** The student's first name. */ protected String firstName; /** The student's last name. */ protected String lastName; /** * The student's current grade. Set to -1 if the student does * not have a grade. */ protected int grade; // +--------------+-------------------------------------------- // | Constructors | // +--------------+ /** * Create a new student record. */ public Student(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; this.grade = -1; } // Student(String) // +-----------+----------------------------------------------- // | Modifiers | // +-----------+ /** * Set the grade of a student. */ public void setGrade(int newgrade) { this.grade = newgrade; } // setGrade() // +------------+---------------------------------------------- // | Extractors | // +------------+ /** * Determine if this student is the same as another student. * Relies on names to make this determination. (It may also * be appropriate to rely on identification number or something * else.) */ public boolean equals(Student other) { return (this.firstName.equals(other.firstName) && this.lastName.equals(other.lastName)); } // equals(Student) /** * Determine if this student is the same as another object. * That object must be a student. */ public boolean equals(Object other) { if (other instanceof Student) { return this.equals((Student) other); } else { return false; } } // equals(Object) /** * Get the grade assigned to the particular student. Returns * -1 if the student does not yet have an assigned grade. */ public int getGrade() { return this.grade; } // getGrade() /** * Generate a string giving the name of the student. */ public String toString() { return this.firstName + " " + this.lastName; } // toString() } // class Student