StudentTester.java /** A class to test the Student class. Solution to Exercise P3.8 */ public class StudentTester
Question:
StudentTester.java
/**
A class to test the Student class.
Solution to Exercise P3.8
*/
public class StudentTester
{
/**
Tests the methods of the Student class.
@param args not used
*/
public static void main(String[] args)
{
Student student = new Student("Jane Doe");
student.addQuiz(8);
student.addQuiz(6);
student.addQuiz(10);
student.addQuiz(8);
System.out.println("Total score for " + student.getName()
+ " = " + student.getTotalScore());
System.out.println("Expected:");
System.out.println("Total score for Jane Doe = 32.0");
System.out.println("Average score for " + student.getName()
+ " = " + student.getAverageScore());
System.out.println("Expected:");
System.out.println("Average score for Jane Doe = 8.0");
student.addQuiz(18);
System.out.println("Total score for " + student.getName()
+ " = " + student.getTotalScore());
System.out.println("Average score for " + student.getName()
+ " = " + student.getAverageScore());
System.out.println("Expected:\nTotal score for Jane Doe = 50.0\nAverage score for Jane Doe = 10.0");
}
}
Student.java (has todo)
/**
A student has a name, total quiz score and number of quizzes
*/
public class Student
{
private String name ; // the name of the student
private int countQuizzes ; // number of quizzes
private double totalQuizScore ; // total score for the student
/**
Constructor method: initialize name with given name1,
set other instance variables to 0
@param name1 the name of the student
*/
public Student(String name1)
{
//-----------Start below here. To do: approximate lines of code = 1
// Complete this constructor
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
countQuizzes = 0 ;
totalQuizScore = 0.0 ;
}
/**
Gets the average quiz score
@return the average of all quizzes
*/
public double getAverageScore()
{
//-----------Start below here. To do: approximate lines of code = 1
// Complete this method
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
/**
Adds on another quiz
@param score the score the student had on the quiz
*/
public void addQuiz(double score)
{
//-----------Start below here. To do: approximate lines of code = 2
// Complete this method
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
/**
Gets the current totalQuizScore level of the student.
@return the current totalQuizScore
*/
public double getTotalScore()
{
//-----------Start below here. To do: approximate lines of code = 1
// Complete this method
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
/**
Gets the name of the student
@return the name
*/
public String getName()
{
//-----------Start below here. To do: approximate lines of code = 1
// Complete this method
//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}
}
P.S: Include screenshots of output so we know the result matches expected
Research Methods Statistics and Applications
ISBN: 978-1452220185
1st edition
Authors: Kathrynn A. Adams, Eva Marie K. Lawrence