import Name; import Address; import java.util.Date; /** * A simple structure for storing information on students. * Intended as an examples for CSC152 2000S HW2. Note that * this class does not provide a way to set parts of a name * or address. Those facilities are parts of the Name and * Address classes. * * See StudentTest.java for examples of how to use this class. * * @author Samuel A. Rebelsky * @version 1.0 of February 2000 */ public class StudentInfo { // +--------+--------------------------------------------------- // | Fields | // +--------+ /** * The student's name. */ protected Name name; /** * The student's ID number. Uses a string because some * ID's include dashes and spaces and other characters. */ protected String id; /** * The student's birthday. Since Java has a built-in Date * class, we use that. */ protected Date birthday; /** * The student's social security number. Since most students * are employees, we can reasonably expect to keep and store * this value. If we don't know the student's social * security number, set this to 0. */ protected String ssn; /** * The student's home address. Set to null if we don't know * the student's home address. */ protected Address home; /** * The student's campus address. Set to null if we don't know * the student's address. If the student lives at home, set * this to the home address. Be careful, though, that if the * student moves to campus, you create a new Address object rather * than changing the fields of an existing one. */ protected Address campus; /** * The student's GPA. Warning! Java approximates floating * point values, so this may be slightly off. We use a * double for a better approximation. If the student has * taken no courses, we set this to 0.0. */ protected double gpa; /** * The student's major. Set to "Undeclared" if the student * has no major. */ protected String major; /** * The student's primary advisor. This should be the advisor * for the specified major. All students must have an * advisor. */ protected FacultyInfo advisor; /** * The student's second major. Set to null if the student only * has one major. If the student has a second major, the * secondAdvisor must be non-null. */ protected String secondMajor; /** * The student's advisor in that major. Set to null if the student * only has one advisor. */ protected FacultyInfo secondAdvisor; /** * The student's concentration. Set to null if the student does * not have a concentration. If the student has a concentration, * the student must also have a concentration advisor. */ protected String concentration; /** * The student's advisor in that concentration. Set to null if the * student does not have a concentraion. */ protected FacultyInfo concentrationAdvisor; /** * The expected graduation year. Use 2000 for 2000 (and not 00). * This could probably be a short, but I'm not being careful about * the amount of space used. */ protected int gradYear; /** * The expected graduation month. 5 for May, 12 for December. * This shouldn't have any other values. This could probably * be a byte, but I'm not being careful about the amount of * space I use. */ protected int gradMonth; // +--------------+--------------------------------------------- // | Constructors | // +--------------+ /** * Create a new student, specifying the minimum information. * If you have more than the initial information, set after * creating the student. */ public StudentInfo(Name initialName, Date whenBorn, String idNumber, FacultyInfo tutorialAdvisor) { /** Set the fields specified as parameters. */ this.name = initialName; this.birthday = whenBorn; this.id = idNumber; this.advisor = tutorialAdvisor; /** Set every other field to a reasonable value. */ this.ssn = null; this.home = null; this.campus = null; this.gpa = 0.0; this.major = "Undeclared"; this.secondMajor = null; this.secondAdvisor = null; this.concentration = null; this.concentrationAdvisor = null; this.gradYear = 2004; this.gradMonth = 5; } // StudentInfo(Name, String, FacultyInfo) // +-----------+------------------------------------------------ // | Accessors | // +-----------+ /** * Get the student's name. */ public Name getName() { return this.name; } // getName() /** * Get the student's birthday. */ public Date getBirthday() { return this.birthday; } // getBirthday() /** * Get the student's ID number. */ public String getID() { return this.id; } // getId() /** * Get the student's SSN. Returns null if we don't know * the student's SSN. */ public String getSSN() { return this.ssn; } // getSSN() /** * Get the student's home address. Returns null if we don't * know the student's home address. */ public Address getHomeAddress() { return this.home; } // getHomeAddress() /** * Get the student's campus address. Returns null if we don't * know the student's campus address. */ public Address getCampusAddress() { return this.campus; } // getCampusAddress() /** * Get the student's GPA. */ public double getGPA() { return this.gpa; } // getGPA() /** * Get the student's major. All students have a major, even * though that major is "Undelcared" for some students. */ public String getMajor() { return this.major; } // getMajor() /** * Get the student's advisor. All students have an advisor. */ public FacultyInfo getAdvisor() { return this.advisor; } // getAdvisor() /** * Get the student's second major. Returns null if the student * is sensible enough to have only one major. */ public String getSecondMajor() { return this.secondMajor; } // getSecondMajor() /** * Get the student's advisor for the second major. Returns null * if the student does not have a second major. */ public FacultyInfo getSecondAdvisor() { return this.secondAdvisor; } // getSecondAdvisor() /** * Get the student's concentration. Returns null if the * student does not have a concentration. Don't forget * technology studies, a great concentration with not * enough students. */ public String getConcentration() { return this.concentration; } // getConcentration() /** * Get the student's advisor for this cool concentration. * Returns null if the student does not have a * concentration. */ public FacultyInfo getConcentrationAdvisor() { return this.concentrationAdvisor; } // getConcentrationAdvisor() /** * Get the year the student is graduating. */ public int getGradYear() { return this.gradYear; } // getGradYear() /** * Get the month the student is graduating. */ public int getGradMonth() { return this.gradMonth; } // getGradMonth() /** * Determine if this student is cool. Students are cool if they * have majors in two different divisions. Students are also * cool if they have a GPA over 3.5 and a concentration. */ public boolean isCool() { // Double major in different divisions. (Or is that required // of all double majors?) if ((this.secondMajor != null) && (getDivision(this.major).equals(getDivision(this.secondMajor)))) return true; // High GPA and concentration. else if ((this.gpa > 3.5) && (this.concentration != null)) return true; // Nope, not cool. else return false; } // isCool() /** * Convert to a string (typically in preparation for printing). * Note that this string is terminated by a carriage return. */ public String toString() { String record = this.name.toString() + "\n"; record = record + "Birthday: " + this.birthday.toString(); record = record + "ID: " + this.id + "\n"; if (this.ssn != null) record = record + "SSN: " + this.ssn + "\n"; if (this.home != null) record = record + "Home address:\n" + this.home.toString(" "); if (this.campus != null) record = record + "Campus address:\n" + this.campus.toString(" "); if (this.gpa == 0.0) record = record + "No GPA recorded.\n"; else record = record + "GPA: " + this.gpa + "\n"; record = record + "Major: " + major + "\n"; record = record + "Advisor: " + advisor.getName().toString(); if (secondMajor != null) { record = record + "Second Major: " + secondMajor + "\n"; record = record + "Advisor for Second Major: " + secondAdvisor.getName().toString() + "\n"; } // the student has a second major. if (concentration != null) { record = record + "Concentration: " + concentration + "\n"; record = record + "Concentration advisor: " + concentrationAdvisor.getName().toString() + "\n"; } // the student has a concentration record = record + "Expected graduation: " + gradMonth + "/" + gradYear; return record; } // toString() // +-----------+------------------------------------------------ // | Modifiers | // +-----------+ /** * Drop a concentration. */ public void dropConcentration() { this.concentration = null; this.concentrationAdvisor = null; } // dropConcentration() /** * Drop a second major. Grinnell doesn't really like double * majors, anyway. */ public void dropSecondMajor() { this.secondMajor = null; this.secondAdvisor = null; } // dropSecondMajor() /** * Drop a first major. Your second major then becomes your first * major. Grinnell doesn't like double majors, so this makes the * powers that be happy. */ public void dropFirstMajor() { this.major = this.secondMajor; this.advisor = this.secondAdvisor; this.secondMajor = null; this.secondAdvisor = null; } // dropFirstMajor() /** * Set the student's name. This is the only way to change a name, * since the Name class does not include any setXXX methods. */ public void setName(Name newName) { this.name = newName; } // setName(String) /** * Set the student's social security number. Set it to null * if you want to forget it. */ public void setSSN(String newSSN) { this.ssn = newSSN; } // setSSN(String) /** * Set the student's home address. Note that you can also change * the home address by getting the home address with getHomeAddress * and then updating that address using setCity or whatever. */ public void setHomeAddress(Address newAddress) { this.home = newAddress; } // setHomeAddress(Address) /** * Set the student's campus address. Note that you can also change * the home address by getting the home address with getHomeAddress * and then updating that address using setCity or whatever. However, * in that case you should make sure that the home and campus addresses * are not the same object. */ public void setCampusAddress(Address newAddress) { this.campus = newAddress; } // setCampusAddress(Address) /** * Set the student's GPA. Should we really care about GPA's? */ public void setGPA(double newGPA) { this.gpa = newGPA; } // setGPA(double) /** * Set the student's major, using a major number. Major * number 1 is the primary major. Major number 2 is * the second major. Major number 3 is the concentration. * Students can't have more than those three. Designed this * way so that you are forced to set both together. */ public void setMajor(int majorNum, String newMajor, FacultyInfo newAdvisor) { if (majorNum == 1) { this.major = newMajor; this.advisor = newAdvisor; } else if (majorNum == 2) { this.secondMajor = newMajor; this.secondAdvisor = newAdvisor; } else if (majorNum == 3) { this.concentration = newMajor; this.concentrationAdvisor = newAdvisor; } } // setMajor(int, String, FacultyInfo) /** * Set the date of graduation. The month should be 5 or 12. * Note that Grinnell discourages early graduation. */ public void setGraduation(int gradYear, int gradMonth) { this.gradYear = gradYear; this.gradMonth = gradMonth; } // setGraduation(int, int) // +---------+-------------------------------------------------- // | Helpers | // +---------+ /** * Determine the division associated with a major. Still needs * some work. */ public static String getDivision(String major) { if (major == null) return "None"; else if (major.equals("American Studies")) return "Social Science"; else if (major.equals("Anthropology")) return "Social Science"; else if (major.equals("Art")) return "Humanities"; else if (major.equals("Biological Chemistry")) return "Science"; else if (major.equals("Biology")) return "Science"; else if (major.equals("Chemistry")) return "Science"; else if (major.equals("Chinese")) return "Humanities"; else if (major.equals("Classics")) return "Humanities"; else if (major.equals("Computer Science")) return "Science"; else if (major.equals("Economics")) return "Social Science"; else if (major.equals("French")) return "Humanities"; else if (major.equals("German")) return "Humanities"; else if (major.equals("History")) return "Social Science"; else if (major.equals("Mathematics")) return "Science"; else if (major.equals("Music")) return "Humanities"; else if (major.equals("Philosophy")) return "Humanities"; else if (major.equals("Physics")) return "Science"; else if (major.equals("Political Science")) return "Social Science"; else if (major.equals("Psychology")) return "Science"; else if (major.equals("Russian")) return "Humanities"; else if (major.equals("Sociology")) return "Social Science"; else if (major.equals("Spanish")) return "Humanities"; else if (major.equals("Theatre")) // Note Grinnell spelling return "Humanities"; else return "None"; } // getDivision() } // class StudentInfo