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.
public class Student {
public Student(String name){
super();
this.name=name;
this.quizNumber=0;
this.quizScore=0;
}
public String getName(){
return name;
}
public void addQuiz(int score){
this.quizScore+=score;
quizNumber++;
}
public int getTotalScore(){
return quizScore;
}
public double getAverageScore(){
return (double)quizScore/quizNumber;
}
private String name;
private int quizScore;
private int quizNumber;
}
public class StudentTester {
/**
* @param args
*/
public static void main(String[] args) {
Student student = new Student("StudentName1");
student.addQuiz(85);
student.addQuiz(70);
student.addQuiz(90);
student.addQuiz(80);
student.addQuiz(86);
System.out.println("Student: "+student.getName());
System.out.println("Total quiz score: "+student.getTotalScore());
System.out.println("Average quiz score: "+student.getAverageScore());
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF