For JAVA ONLY please Objects Chapter 4) Implement a class Student. For the purpo
ID: 3766886 • Letter: F
Question
For JAVA ONLY please
Objects Chapter
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 need to store the number of quizzes the student took.
Write a program that demonstrates the methods for a group of at least 4 students using an ArrayList to hold Student objects.
if you could print the output I would be very greatful !! Thank you !!
Explanation / Answer
public class Student { // instance variables private String name; private double quizScore; /** * Constructs a Student object with a name "RickyBobby" and zero total quiz score */ public Student() { name = "RickyBobby"; quizScore = 0; } /** * Constructs a Student object with an initial name and total quiz score */ public Student(String pName, double pQuizScore) { name = pName; quizScore = pQuizScore; } /** * Returns the name of a student * * @return the name of the student */ public String getName() { return name; } /** * Adds a quiz score to the total quiz score of the student * * @param score the score of a quiz */ public void addQuiz(int score) { quizScore = quizScore + score; } /** * Returns the total score of all the quizzes combined of the student * * @return the value of quizScore */ public double getTotalScore() { return quizScore; } /** * Returns the average score of all the quizzes a student took * * @return */ public double getAverageScore() { //getAverageScore code goes here } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.