Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming Exercise 1 (StudentGrades class) Implement a class Student, a studen

ID: 3746943 • Letter: P

Question

Programming Exercise 1 (StudentGrades class) Implement a class Student, a student has a name and total quiz score. Supply an appropriate constructor and methods getName0, 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 StudentTest class to test all methods and functionalities of this exercise. You may have a maximum of 4 tests. A constructor must be iniialized in the following manner Student stud new Student("John Smith", 100,80,50,70) Output display: Student name: John Smith Total Score 300 Score average: 75 The, user must be prd to enteran stadent data

Explanation / Answer

import java.util.Scanner; class StudentGrades { private String name; private int scores; private int count; public StudentGrades(String name, int s1, int s2, int s3, int s4) { this.name = name; this.scores = s1 + s2 + s3 + s4; count = 4; } public String getName() { return name; } public int getTotalScore() { return scores; } public double getAverageScore() { return scores / (double)count; } public void addQuiz(int score) { scores += score; count++; } } class StudentTest { public static void main(String[] args) { StudentGrades stud1 = new StudentGrades("John smith", 100, 80, 50, 70); System.out.println("Student name: " + stud1.getName()); System.out.println("Total score: " + stud1.getTotalScore()); System.out.println("Score average:" + stud1.getAverageScore()); Scanner in = new Scanner(System.in); System.out.print("Enter name: "); String name = in.nextLine(); System.out.print("Enter 4 scores: "); StudentGrades stud2 = new StudentGrades(name, in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt()); System.out.println("Student name: " + stud2.getName()); System.out.println("Total score: " + stud2.getTotalScore()); System.out.println("Score average:" + stud2.getAverageScore()); System.out.print("Enter another score: "); stud2.addQuiz(in.nextInt()); System.out.println("Total score: " + stud2.getTotalScore()); System.out.println("Score average:" + stud2.getAverageScore()); } }