Question
Using Java, Modify THE FOLLOWING PROGRAM to compute grade point averages. Methods are needed to add a grade and get the current GPA. Specify grades
Using Java, Modify THE FOLLOWING PROGRAM 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).
import java.util.Scanner; public class LabStudents {
// declaring constructor variable String name; int totalQuizScore; int numberOfQuizzes;
// building constructor public LabStudents(String name) { this.name = name; // assigning name value to the constructor value this.totalQuizScore = 0; this.numberOfQuizzes = 0; }
// returning name which is assigned to the constructor variable public String getName() { return this.name; }
// returning quiz score which is assigned to the constructor variable public int getTotalScore() { return this.totalQuizScore; }
public void addQuiz(int score) { this.numberOfQuizzes++; // increments quiz count this.totalQuizScore += score;// adding quiz score }
// returning average score by dividing quiz score and no.of quizzes public double getAverageScore() { return this.totalQuizScore / this.numberOfQuizzes; }
// starting main method here public static void main(String args[]) {
Scanner sc = new Scanner(System.in); // Scanner object creation int score; // int ch = sc.nextInt(); System.out.print("Enter Student Name : "); String name = sc.nextLine(); // taking name System.out.println("Enter Total Quiz Score: "); score = sc.nextInt();// taking score
LabStudents s = new LabStudents(name); // Student object creation
s.addQuiz(score);// adding score by calling method while (true) { // infinite loop for asking input each time System.out.println("Choose Y for Add another grade to the student or Any other for exit"); char ch = sc.next().charAt(0);// taking first char from input // checking yes or no if (ch == 'Y' || ch == 'y') { System.out.println("Enter Total Quiz Score: "); score = sc.nextInt();// taking quiz score s.addQuiz(score); } else { // displaying results System.out.println("Total Score : " + s.getTotalScore()); System.out.println("Total Average: " + s.getAverageScore()); System.out.println("Total Quizzes Attempted: " + s.numberOfQuizzes); break; } } } }
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