Question
JAVA. Modify the Student class of Lab6 to compute grade point averages. Methods are needed to add a grade and get the current GPA. Specify
JAVA. Modify the Student class of Lab6 to compute grade point averages. Methods are needed to add a grade and get the current GPA. Specify grades as elements of a class Grade. Supply a constructor that constructs a grade from a string, such as "B+". You will also need a method that translates grades into their numeric values (for example, "B+" becomes 3.3).
Here is my student class:
/**
*
* @author rhiannondore
* 2/10/19
* This is a class of constructors and methods used with StudentTester to get the names and average quiz scores of students
*
*/
public class Student {
//declare variables
String name;
int totalQuizScore;
int numOfQuizzes;
public Student(String name) {
this.name = name;
this.totalQuizScore = 0;
this.numOfQuizzes = 0;
}//main
//implement getName method
public String getName() {
return this.name;
}//getName
//implement getTotalScore method
public int getTotalScore() {
return this.totalQuizScore;
}//getTotalScore
//implement addQuiz method
public void addQuiz(int score) {
this.numOfQuizzes++;
this.totalQuizScore += score;
}//addQuiz
//implement getAverageScore method
public double getAverageScore() {
return this.totalQuizScore / this.numOfQuizzes;
}//getAverageScore
}//classStudent
Here is my studentTester class:
* Created by Rhiannon Dore * 2/4/19 * This is a tester class to prompt the user for a name and set of test scores that then displays them */ import java.util.Scanner;
public class StudentTester{
public static void main(String[] args) { //import scanner Scanner in = new Scanner(System.in);
//prompt user for student name System.out.print("Enter the student's first name: "); String name = in.next(); Student std = new Student(name);
//prompt user for quiz scores System.out.print("Enter a quiz score rounded to the nearest whole number(-1 to exit): "); int score = in.nextInt(); while(score>=0){ std.addQuiz(score); System.out.print("Enter a quiz score rounded to the nearest whole number(-1 to exit): "); score = in.nextInt();
}
//print name, total score, and average score System.out.println("Name: "+std.getName()); System.out.println("Total Score: "+std.getTotalScore()); System.out.println("Average Score: "+std.getAverageScore());
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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