Question
StudentTester.java /** A class to test the Student class. Solution to Exercise P3.8 */ public class StudentTester { /** Tests the methods of the Student
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
A student has a name, total quiz score and number of quizzes See the following files: * StudentTester.java * Student.java (has todo) Approximate total lines of code required: 6
Step by Step Solution
3.44 Rating (151 Votes )
There are 3 Steps involved in it
Step: 1
StudentTesterjava A class totest the Student class Solution toExercise P38 public class StudentTester Tests the methodsof the Student class param args ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started