Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- public class Student {
- private String firstName, lastName;
- private Address homeAddress, schoolAddress;
- private int testNumber; // Contains the test number
- private double testScore; // Contains the value of the tests
- private double[] testScores;
- public Student(String first, String last, Address home, Address school, double[] testScores1) {
- firstName = first;
- lastName = last;
- homeAddress = home;
- schoolAddress = school;
- int numberOfScores = testScores1.length;
- this.testScores = testScores1;
- }
- public void setTestScore(int testNumber, double testScore) {
- this.testNumber = testNumber;
- this.testScore = testScore;
- }
- public double getTestScore (int testNumber) {
- return testScore;
- }
- // Initialize values with 0
- public Student() {
- Arrays.fill(testScores, 0);
- }
- // Find the average of the test scores
- public double average() {
- int i;
- double total = 0;
- double averageScore = 0;
- for(i=0; i<testScores.length; i++) {
- total = total + testScores[i];
- }
- averageScore = total / testScores.length;
- return averageScore;
- }
- /* (non-Javadoc)
- * @see java.lang.Object#toString()
- */
- @Override
- public String toString() {
- return "Student [firstName=" + firstName + ", lastName=" + lastName
- + ", homeAddress=" + homeAddress + ", schoolAddress="
- + schoolAddress + ", testScores="
- + ", average()=" + average() + "]";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement