0% found this document useful (0 votes)
144 views

Implement A Class

The document describes a Student class that tracks a student's name, quiz scores taken, total score, and average score. It provides a constructor to initialize the student with a name, and methods to get the name, add a quiz score, get the total score, and get the average score. It also includes a StudentTester class to test the Student class methods.

Uploaded by

Nikitaa Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views

Implement A Class

The document describes a Student class that tracks a student's name, quiz scores taken, total score, and average score. It provides a constructor to initialize the student with a name, and methods to get the name, add a quiz score, get the total score, and get the average score. It also includes a StudentTester class to test the Student class methods.

Uploaded by

Nikitaa Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Implement a class Student . For the purpose of this exercise, a student has a name and a total quiz score.

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;

/** Constructs a student with a given name. * @param name */

public Student (String name) { name = "Billy"; quizzestaken = 3;

/** 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; }

You might also like