Question: Final Grade. The errors only errors that come up are that 'letterGrade' may not have been initialized. The code is exactly how it's supposed to

Final Grade.

The errors only errors that come up are that 'letterGrade' may not have been initialized. The code is exactly how it's supposed to be, I don't need any changes, but I can't figure out why that error message is there.

import java.util.Scanner;

public class FinalExam {

public static void main(String[] args){

// declaring all variables

Scanner in = new Scanner (System.in);

int choice;

double quiz;

double asign;

double project;

double Final;

double current;

double grade;

char letterGrade;

// displaying the menu

System.out.println("Please enter your choice of grade");

System.out.println();

System.out.println("1.\t A: 90-100");

System.out.println("2.\t B: 80-89.9");

System.out.println("3.\t C: 70-79.9");

System.out.println("4.\t D: 60-69.9");

System.out.println("5.\t F: 0-59.9");

System.out.println("6.\t You would like to exit the program");

//getting users choice

choice = in.nextInt();

// Displaying choice

switch (choice) {

case 1: System.out.println("You selected, A");

Final = 90;

letterGrade = 'A';

break;

case 2: System.out.println("You selected, B");

Final = 89.9;

letterGrade = 'B';

break;

case 3: System.out.println("You selected, C");

Final = 79.9;

letterGrade ='C';

break;

case 4: System.out.println("You selected, D");

Final = 69.9;

letterGrade = 'D';

break;

case 5: System.out.println("You selected, F");

Final = 59.9;

letterGrade = 'F';

break;

case 6: System.out.println("Exiting the program");

System.exit(0);

System.out.println("Ending the program");

break;

default: System.out.println("invaild choice");

}

//getting grades from student to claculate the final grade

System.out.println("Please enter your Quiz average");

quiz = in.nextDouble();

System.out.println("Please enter your Assignment average");

asign = in.nextDouble();

System.out.println("Please enter your Project average");

project = in.nextDouble();

//doing the math for the final grade

current = (.20 * asign + .20 * quiz + .20 * project);

grade = (Final - current) / .40;

// output

if (grade > 100){

System.out.println("You would need to make over 100 to pass the class for an" + letterGrade);

}else if (grade <= 0){

System.out.println("You do not have to take the final to get that grade to get a" + letterGrade);

}else {

System.out.printf("To make a" + letterGrade + "in the class, you at least need to make a a:%.3f ", grade);

}

}

}

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 Databases Questions!