Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Student Class

By: a guest on Jan 8th, 2013  |  syntax: Java  |  size: 2.08 KB  |  views: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. /**
  3.  * Write a description of class Student here.
  4.  *
  5.  * Stefan Howansky
  6.  * @version (a version number or a date)
  7.  */
  8. public class Student
  9. {
  10.     // instance variables
  11.     private int test1;
  12.     private int test2;
  13.     private int test3;
  14.     private String name;
  15.    
  16.     /*
  17.      *Constructor
  18.      */
  19.     public Student()
  20.     {
  21.         name = "";
  22.         test1 = 0;
  23.         test2 = 0;
  24.         test3 = 0;
  25.     }
  26.  
  27.     public Student(int t1, int t2, int t3, String nm)
  28.     {
  29.         name = nm;
  30.         test1 = t1;
  31.         test2 = t2;
  32.         test3 = t3;
  33.     }
  34.  
  35.  
  36.     /*
  37.      *MUTATOR METHOD
  38.      */
  39.     public void setName(String nm)                          //Sets the student's name
  40.     {
  41.         name=nm;
  42.     }
  43.  
  44.     /*
  45.      * ACCESSOR METHOD
  46.      */
  47.     public String getName()                                 //Gets the student's name
  48.     {  
  49.         return name;
  50.     }
  51.  
  52.  
  53.  
  54.     public void setGrade(int t1, int t2, int t3)
  55.     {
  56.         test1 = t1;
  57.         test2 = t2;
  58.         test3 = t3;
  59.     }
  60.  
  61.  
  62.     /*
  63.      * returns the grade asked for by the input parameter
  64.      */
  65.     public int getGrade(int t)
  66.     {
  67.        if (t==1)
  68.             return test1;
  69.  
  70.       else if (t==2)
  71.        {
  72.        return test2;
  73.     }
  74.        else
  75.        {
  76.        return test3;
  77.     }
  78.     }
  79.  
  80.     public int sumGrades()
  81.     {
  82.     return (test1 + test2 + test3);
  83.     }
  84.  
  85. public double calculateAverage()
  86. {
  87.     double average;
  88.     average = sumGrades()/3.0;
  89.    
  90.     return average;
  91. }
  92.  
  93.     public String toString()
  94.     {
  95.     String str;
  96.     str = "Name:      " + name   + "\n" +
  97.           "Test 1:    " + test1  + "\n" +
  98.           "Test 2:    " + test2  + "\n" +
  99.           "Test 3:    " + test3  + "\n" +
  100.           "Sum:       " + sumGrades()+ "\n" +
  101.           "Average:   " + calculateAverage();
  102.          
  103.           return str;
  104.         }
  105. public boolean compareStudent(Student s2)
  106. {
  107.         if(this.toString().equals(s2.toString()))
  108.             return true;
  109.          else
  110.             return false;
  111.        //this.toString == other.toString;
  112. }
  113. }
clone this paste RAW Paste Data