The courses you entered are: Grades Hours A 4 A Resulting in a GPA of 0.0 un N The courses you entered are: Grades Hours A 3 В 4 A 5 в 2. Resulting in a GPA of 3.6 n

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hello! I am new to Java and am struggling heavily with a current assignment. I got the output to look as desired, but the respective GPA is not functioning at all.

My logic is to convert each letter grade into a number and multiply that by credit hours in that class. I will then add the result of this calculation for each class together and divide it by the total number of credits the student is undertaking.

I have included images of the criteria model output (white) compared to my own (grey). 

I should add that we are intended to use a "do while" loop, but I could not get mine to break, which is why I added an additional break statement.

 

import java.util.Scanner;
public class GpaCalculator {

public static void main (String args[]){

Scanner inKey = new Scanner (System.in);

double gpa = 3;

String letInput = "";
int grade = 0,earned = 0,finHrs = 0;
String outResult = "";
int hourInput = 0;

do {
System.out.println("What letter grade do you have in this Class? (Without +/-) (Enter Q to quit)");
letInput = inKey.nextLine();

if (letInput.toUpperCase().equals("Q")){
break;
}

if (letInput.toUpperCase().equals("A")) {
grade = 4;
}
if (letInput.toUpperCase().equals("B")) {
grade = 3;
}
if (letInput.toUpperCase().equals("C")) {
grade = 2;
}
if (letInput.toUpperCase().equals("D")) {
grade = 1;
} else {
grade = 0;
}

System.out.println("How many hours was this class worth?");
hourInput = Integer.parseInt(inKey.nextLine());

finHrs += hourInput;

earned += grade * hourInput;

outResult += letInput+"\t\t"+ hourInput + "\n";


}while(!letInput.toUpperCase().equals("Q"));

double newEarned = earned,newHrs = finHrs;
gpa = newEarned/newHrs;
String gradeDisplay = "The courses you entered are:\nGrades\tHours\n"+outResult+"\nResulting in a GPA of "+gpa;
System.out.println(gradeDisplay);
}

}

The courses you entered are:
Grades
Hours
A
4
A
Resulting in a GPA of 0.0
un N
Transcribed Image Text:The courses you entered are: Grades Hours A 4 A Resulting in a GPA of 0.0 un N
The courses you entered are:
Grades
Hours
A
3
В
4
A
5
в
2.
Resulting in
a GPA of 3.6
n
Transcribed Image Text:The courses you entered are: Grades Hours A 3 В 4 A 5 в 2. Resulting in a GPA of 3.6 n
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Adjacency Matrix
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education