package StudentPkg; /* * Student.java * * Created on September 20, 2001, 11:06 AM * Modified January 6, 2002 - removed the readStudent method. * it now resides in the StudentFile class. * This class represents on student. * * @author Stuart Hansen * @version */ import java.io.*; public class Student implements Serializable { private String name; // the name of the student private int exam1; // the first exam grade private int exam2; // the second exam grade private int exam3; // the third exam grade /** Create a new student with no assigned attributes **/ private Student () { } /** Creates new Student */ public Student(String name, int exam1, int exam2, int exam3) { this.name = name; this.exam1 = exam1; this.exam2 = exam2; this.exam3 = exam3; } /** Convert a student to a string **/ public String toString() { return (getName() + " " + getExam1() + " " + getExam2() + " " + getExam3()); } /** Setters and Getters for the students */ /** Get or set the student's name **/ public String getName() {return name;} public void setName(String name) {this.name = name;} /** Get or set the exam scores **/ public int getExam1() {return exam1;} public void setExam1(int exam) {exam1 = exam;} public int getExam2() {return exam2;} public void setExam2(int exam) {exam2 = exam;} public int getExam3() {return exam3;} public void setExam3(int exam) {exam3 = exam;} /** returns the average of the three exams **/ public double getAverage() {return (double)(exam1+exam2+exam3)/3.0;} public static Student readStudentFromKeyboard() { Student tempStudent = new Student(); try { InputStreamReader reader = new InputStreamReader (System.in); StreamTokenizer strtok = new StreamTokenizer(reader); System.out.print ("Enter the student's name ==> "); strtok.nextToken(); tempStudent.name = strtok.sval; System.out.print ("Enter the three exam scores (separated by spaces) ==> "); strtok.nextToken(); tempStudent.exam1 = (int)strtok.nval; strtok.nextToken(); tempStudent.exam2 = (int)strtok.nval; strtok.nextToken(); tempStudent.exam3 = (int)strtok.nval; } catch (Exception e) { System.out.println ("Exception Occurred!! " + e); } return tempStudent; } }