Question
------Write a program that has variables to hold three test scores. The program should ask the user to enter three test scores and then assign
------Write a program that has variables to hold three test scores. The program should ask the user to enter three test scores and then assign the values entered to the variables. The program should display the average of the test scores and the letter grade that is assigned for the test score average.
Use the grading scheme in the following table:
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F------
I have my code written out already, but I am getting an error from this code that says "The local variable letterGrade may not have been initialized"
Here is my code:
import java.util.Scanner;
public class NAM_TestScoresAndGrade { public static void main(String[] args) {
double test1, test2, test3, averageScore; char letterGrade; Scanner sc = new Scanner(System.in); test1 = sc.nextDouble(); test2 = sc.nextDouble(); test3 = sc.nextDouble(); averageScore = (test1 + test2 + test3)/3; System.out.print("Enter first test score"); System.out.print("Enter second test score"); System.out.print("Enter third test score"); if (averageScore >= 90 && averageScore <= 100) { letterGrade = 'A'; } else if (averageScore >= 80 && averageScore <= 89) { letterGrade = 'B'; } else if (averageScore >= 70 && averageScore <= 79) { letterGrade = 'C'; } else if (averageScore >= 60 && averageScore <= 69) { letterGrade = 'D'; } else if (averageScore < 60) { letterGrade = 'F'; } System.out.println("Average score: " + averageScore); System.out.println("Letter grade: " + letterGrade); sc.close(); } }
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