package rebelsky.student; /** * A simple representation of students (at Grinnell and * elsewhere). Written as a partial sample solution for Exam 1 * in CSC152 2004F. *

* Note that the code currently has a hardwired "all * students with unspecified year are assumed to * graduate in 2008". That code should be corrected. *

* This class is only partially implemented. Do not take it * as the full answer key for this part of Exam 1. * * @author Samuel A. Rebelsky * @version 1.0 of October 2004 */ public class Student { // +--------+-------------------------------------------------- // | Fields | // +--------+ /** * The student's last name. Can be more than one word, * if necessary (e.g., van der Sky). */ String lname; /** * The student's first name. */ String fname; /** * The student's ID number. Leading zeroes are * dropped. */ long id; /** * The student's graduating class. Please use the * full year (2004, not 04). */ int gradClass; /** * The student's intended major. Sorry, we only allow * one major right now. */ String major; // +--------------+-------------------------------------------- // | Constructors | // +--------------+ /** * Create a new student by supplying all requisite * information. */ public Student(String _lname, String _fname, long _id, int _gradClass, String _major) { this.lname = _lname; this.fname = _fname; this.id = _id; this.gradClass = _gradClass; this.major = _major; } // Student(String, String, long, int, String) /** * Create a new student, supplying only name. */ public Student(String _lname, String _fname) { this.lname = _lname; this.fname = _fname; this.id = (long) (Long.MAX_VALUE * Math.random()); this.gradClass = 2008; this.major = "Undeclared"; } // Student(String, String) // +----------+------------------------------------------------ // | Mutators | // +----------+ // +-----------+----------------------------------------------- // | Observers | // +-----------+ /** * Get the student's full name (in lname-comma-fname form). */ public String getName() { return this.lname + ", " + this.fname; } // getName() /** * Convert to a string for ease of printing. */ public String toString() { return this.fname + " " + this.lname + " " + this.gradClass + "(ID: " + this.id + ", Major: " + this.major + ")"; } // toString() } // class Student