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
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F87ef5068-8110-4421-80d2-30aa5fdea14d%2F5c25e82f-47cb-499c-8fc9-2b1bae1153c4%2Fwrqmm5f.png&w=3840&q=75)
![The courses you entered are:
Grades
Hours
A
3
В
4
A
5
в
2.
Resulting in
a GPA of 3.6
n](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F87ef5068-8110-4421-80d2-30aa5fdea14d%2F5c25e82f-47cb-499c-8fc9-2b1bae1153c4%2Fl37ylx4.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)