Advertisement
droidus

student

Oct 5th, 2011
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. public class Student {
  4.     private String firstName, lastName;
  5.     private Address homeAddress, schoolAddress;
  6.     private int testNumber; // Contains the test number
  7.     private double testScore; // Contains the value of the tests
  8.     private double[] testScores;
  9.  
  10.     public Student(String first, String last, Address home, Address school, double[] testScores1) {
  11.         firstName = first;
  12.         lastName = last;
  13.         homeAddress = home;
  14.         schoolAddress = school;
  15.        
  16.         int numberOfScores = testScores1.length;
  17.         this.testScores = testScores1;
  18.     }
  19.  
  20.     public void setTestScore(int testNumber, double testScore) {
  21.         this.testNumber = testNumber;
  22.         this.testScore = testScore;
  23.     }
  24.    
  25.     public double getTestScore (int testNumber) {
  26.         return testScore;
  27.     }
  28.  
  29.     // Initialize values with 0
  30.     public Student() {
  31.         Arrays.fill(testScores, 0);
  32.     }
  33.  
  34.     // Find the average of the test scores
  35.     public  double average() {
  36.         int i;
  37.         double total = 0;
  38.         double averageScore = 0;
  39.  
  40.         for(i=0; i<testScores.length; i++) {
  41.             total = total + testScores[i];
  42.         }
  43.  
  44.         averageScore = total / testScores.length;
  45.        
  46.         return averageScore;
  47.     }
  48.  
  49.     /* (non-Javadoc)
  50.      * @see java.lang.Object#toString()
  51.      */
  52.     @Override
  53.     public String toString() {
  54.         return "Student [firstName=" + firstName + ", lastName=" + lastName
  55.                 + ", homeAddress=" + homeAddress + ", schoolAddress="
  56.                 + schoolAddress + ", testScores="
  57.                 + ", average()=" + average() + "]";
  58.     }
  59.    
  60. }
  61.  
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement