implement a class

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 methods getName() , 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 St udentTester {  public static voi d main(String[] args) { Student student = new S tudent("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 St udent { /** 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 sc ore) { . . . } /** Gets the sum of all quiz scores. @return the total score

Upload: nikitaa-gupta

Post on 19-Oct-2015

20 views

Category:

Documents


0 download

DESCRIPTION

java code

TRANSCRIPT

Implement a classStudent. 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(), andgetAverageScore(). To compute the latter, you also need to store thenumber of quizzesthat the student took. Supply aStudentTesterclass 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; } }