Write a Java program that calculates a student’s GPA.
- While loops
- Switch statements
Write a Java program that asks the user to enter seven different grades and then calculates the GPA from those grades.
- Grades are entered as letters, upper or lowercase.
- Read grades in as a string, but convert them to a character. Use the .charAt(0) command to do this.
- Use a Switch statement to convert letter grades to numbers with the following conversion:
- A = 4 points
- B = 3 points
- C = 2 points
- D = 1 point
- F = zero points
- Anything else asks the user to re-enter the grade.
- GPA is calculated by adding up the total points and dividing by the number of classes.
- Use a while loop with a counter variable to input the grades.
- Invalid grades should not be counted in the calculation of the GPA.
- Output the final GPA. You do not have to output the letter grades.
- Make sure to test with all grade input options, including upper/lower case and invalid ones.
- Verify the GPA calculation is correct.
- You can read in either a Char or String. Strings are sometimes easier to work with, though, and won’t crash with numbers, words, or strange characters.
- You do not necessarily have to save the grades as individual variables. You can just run your calculations on them after you read them in.
Edhesive Term 1
Lesson 17: While loops
Lesson 19: While loops with modular
Lesson 20: While loops with flag