Implement A Class
Implement A Class
Supply an appropriate constructor and methodsgetName() , addQuiz(int score) , getTotalScore() , and getAverageScore() . To compute the latter, you also need to store the number of quizzes that the student took. Supply a StudentTester class that tests all methods. Complete the following class as your tester class:
/** This program tests the Student class. */ public class StudentTester { public static void main(String[] args) { Student student = new Student("Cracker, Carla"); // TODO: Add some quizzes // TODO: Print actual and expected name, total score } } Complete the following class in your solution: /** A student who is taking quizzes. */ public class Student { /** Constructs a student with a given name. @param n the name */ public Student(String n) { ... } /** Gets the name of this student. @return the name */ public String getName() { ... } /** Adds a quiz score. @param score the score to add */ public void addQuiz(int score) { ... } /** Gets the sum of all quiz scores. @return the total score
*/ public double getTotalScore() { ... } /** Gets the average of all quiz scores. @return the average score */ public double getAverageScore() { ... } ... }
public class Student { //instance fields private double score; private String name; private double quizzestaken;
/** Gets the name of this student. @return the name */ public String getName() { return name; }
/** Adds a quiz score. @param score the score to add */ public void addQuiz(int score) { score = 24; }
/** Gets the sum of all quiz scores. @return the total score */ public double getTotalScore() { return score;
/** Gets the average of all quiz scores. @return the average score */ public double getAverageScore() { double averageScore = (score / quizzestaken); return averageScore; }