Source of Student.java


  2: /**
  3:  * A class to hold some very basic information about a student.
  4:  *
  5:  * @author Mark Young (A00000000)
  6:  */
  7: public class Student {

  9:     /** The student's A-Number */
 10:     public final String aNumber;
 11:     /** The student's name */
 12:     private String name;
 13:     /** The student's grade (as a percentage) */
 14:     private int pctGrade;

 16:     /**
 17:      * Create a Student object.
 18:      *
 19:      * @param aNumber   the requested A-Number (must be A + 8 digits)
 20:      * @param name      the requested name
 21:      * @param pctGrade  the requested percentage grade (must be 0..100)
 22:      */
 23:     public Student(String aNumber, String name, int pctGrade) {
 24:         this.aNumber = aNumber;
 25:         this.name = name;
 26:         if (0 <= pctGrade && pctGrade <= 100) {
 27:             this.pctGrade = pctGrade;
 28:         } else {
 29:             this.pctGrade = 0;
 30:         }
 31:     }

 33:     /**
 34:      * Get the value of aNumber
 35:      *
 36:      * @return the value of aNumber
 37:      */
 38:     public String getANumber() {
 39:         return aNumber;
 40:     }

 42:     /**
 43:      * Get the value of pctGrade
 44:      *
 45:      * @return the value of pctGrade
 46:      */
 47:     public int getPctGrade() {
 48:         return pctGrade;
 49:     }

 51:     /**
 52:      * Set the value of pctGrade
 53:      *
 54:      * @param pctGrade  new value of pctGrade (must be 0..100)
 55:      */
 56:     public void setPctGrade(int pctGrade) {
 57:         if (0 <= pctGrade && pctGrade <= 100) {
 58:             this.pctGrade = pctGrade;
 59:         }
 60:     }

 62:     /**
 63:      * Get the value of name
 64:      *
 65:      * @return the value of name
 66:      */
 67:     public String getName() {
 68:         return name;
 69:     }

 71:     /**
 72:      * Set the value of name
 73:      *
 74:      * @param name new value of name
 75:      */
 76:     public void setName(String name) {
 77:         this.name = name;
 78:     }

 80:     /**
 81:      * Change both name and grade.
 82:      *
 83:      * @param n     requested new name
 84:      * @param g     requested new grade (must be 0..100)
 85:      */
 86:     public void set(String n, int g) {
 87:         this.setName(n);
 88:         this.setPctGrade(g);
 89:     }

 91:     /**
 92:      * Print a brief summary of the student's data.
 93:      */
 94:     public void printStudentRecord() {
 95:         System.out.println("Number: " + aNumber);
 96:         System.out.println("Name:   " + name);
 97:         System.out.println("Grade:  " + pctGrade);
 98:     }

100: }