Question: 5 4 . 9 Project: Calculate Weighted GPA Write a program that prompts the user for the letter grades and associated credit hours for four

54.9 Project: Calculate Weighted GPA
Write a program that prompts the user for the letter grades and associated credit hours for four classes and output the weighted GPA. The number of credit hours is an integer. In order to convert the letter grade to its GPA form, use the code from the LetterToGPA lab. You will need to use the if statement that you developed to convert the letter grade to GPA only and not the one used for checking valid input. We are not checking for invalid input in this project. As the user enters grades and credit hours for four courses, you will want to keep a running sum of GPA and the total number of credit hours to compute the weighted GPA as per the formula below:
Letter Grade Grade's Numerical Value
A 4.0
A-3.7
B+3.3
B 3.0
B-2.7
C+2.3
C 2.0
C-1.7
D+1.3
D 1.0
E 0.0
This formula essentially means that for each class, you take a grade as input (each letter grade will have a corresponding GPA that you need to associate with it) and multiply the GPA by the class's credit hours. For instance, if you input A and 3, the calculation would be 4.0 x 3, which would yield 12.
Let's take a look at an example below with the following course grades and credit hours as input:
Sample Example:
Grade Credits
A 4
B-2
B 2
C+3
Since we only take four classes as input, we do four different multiplications, sum their results, and divide by the total number of credits hours provided as input.
Step 1:
We will compute each multiplication of GPA and credit hour calculation.
1st Multiplication (Class 1): Input: A and 4
Multiplication Result: 4.0*4=12
2nd Multiplication (Class 2): Input: B- and 2
Multiplication Result: 2.7*2=5.4
3rd Multiplication (Class 3): Input: B and 2
Multiplication Result: 3.0*2=6.0
4th Multiplication (Class 4): Input: C+ and 3
Multiplication Result: 2.3*3=6.9
We will now add these values together to obtain the numerator portion of the formula.
Step 2:
We will now add these values and divide by the total number of credit hours we have provided as input.
Total Credit Hours: 4+2+2+3=11
Step 3:
We will now divide the numerator by the denominator to obtain our final result for our calculated weighted GPA.
All Steps together Using Formula:
Learning Objective: To use for loops and iterative variable updates.
Sample Outputs: This is a sample transcript of what your program should do. Make sure your output looks EXACTLY like the output below, including spacing.
Sample run 1:
Please insert the letter grades and credit hours for your four classes below once prompted.
Enter a letter grade: A
Enter the associated credit hours: 4
Enter a letter grade: B-
Enter the associated credit hours: 3
Enter a letter grade: A-
Enter the associated credit hours: 5
Enter a letter grade: B+
Enter the associated credit hours: 2
GPA | Credit
-------------------
4.0|4.0
2.7|3.0
3.7|5.0
3.3|2.0
Your Final GPA is: 3.5142857142857147
Goodbye!
Sample run 2:
Please insert the letter grades and credit hours for your four classes below once prompted.
Enter a letter grade: A
Enter the associated credit hours: 4
Enter a letter grade: B
Enter the associated credit hours: 3
Enter a letter grade: C
Enter the associated credit hours: 2
Enter a letter grade: D
Enter the associated credit hours: 1
GPA | Credit
-------------------
4.0|4.0
3.0|3.0
2.0|2.0
1.0|1.0
Your Final GPA is: 3.0
Goodbye!
Hints:
You will need to write a loop to take in all the classes.
You will want to keep a string variable that holds the table that you want to print, and every time you loop, you will want to add a new table line to the end of that string. You can start a new line with the character
". We also use tabs instead of spaces in our table, which can be added by writing \t in your string.
Start with a GPA =0 and add on the weighted GPA for each class.
You can then divide by the total credit hours at the end of your while loop to get the weighted GPA. When you do this, try multiplying the summed weighted GPA by 1.0 in order to switch to a floating point division instead of an integer division.
553700.4422302.qx3zqy7
lab activity
54.9.1: Project: Calculate Weighted GPA
/**
* DESCRIPTION OF PROGRAM HERE
*
* @author YOUR NAME HERE
* @version DATE HERE
*/
import java.util.Scanner;
public class LetterToGPA {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
/* Type your code here. */
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!