Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab#1: Student Class (Continued) (Part c) Computing student average quiz score.

ID: 3724116 • Letter: L

Question

Lab#1: Student Class (Continued) (Part c) Computing student average quiz score. Use the classes that we already have (Student and Studentester in Lab#1 part b) and do the following: In Student class: Add one more attribute (total quiz score) to Student; .Add the following methods: e addQuiz (int score) getTotalScore() . getAverageScore(). Note: To computer the average grade, you also need to store the number of quizzes that the student took In StudentTester class: Considering that sti has taken 5 quizzes and has scored 89, 100, 90, 80, 75, compute and display the total score and the average score

Explanation / Answer

StudentTester.java

public class StudentTester {

public static void main(String[] args) {

Student s = new Student("Suresh");

s.addQuiz(89);

s.addQuiz(100);

s.addQuiz(90);

s.addQuiz(80);

s.addQuiz(75);

System.out.println("Student Name: "+s.getName());

System.out.println("Total Quiz Score: "+s.getTotalScore());

System.out.println("Average Quiz Score: "+s.getAverageScore());

}

}

Student.java

public class Student {

private String name;

private int numOfQuizzesTaken;

private int totalScore;

public Student(String name){

this.name = name;

}

public String getName() {

return name;

}

public int getTotalScore() {

return totalScore;

}

public void addQuiz(int score) {

totalScore = totalScore + score;

numOfQuizzesTaken++;

}

public double getAverageScore(){

return totalScore/(double)numOfQuizzesTaken;

}

}

Output:

Student Name: Suresh
Total Quiz Score: 434
Average Quiz Score: 86.8