This is the first time I have ever attempted to make a program. Java is completely new to me.
I thought the program I was working on would be too hard, but I'm stuck and don't know what it did wrong.
My compiler has been telling me that a variable may not have been initialized, and I don't know how to fix this.
Help please!
This is my code:
import java.util.Scanner; /** This program prompts the user to enter a letter grade and prints its numeric value.*/ public class GradeNumber { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Please enter the letter grade: "); String letterGrade = in.next(); String letter = letterGrade.substring(0,1); String sign = letterGrade.substring(1); double numericValue; if (letter.equals("A") || letter.equals("B") || letter.equals("C") || letter.equals("D") || letter.equals("E")) { if (letter.equals("A")) { numericValue = 4; } else if (letter.equals("B")) { numericValue = 3; } else if (letter.equals("C")) { numericValue = 2; } else if (letter.equals("D")) { numericValue = 1; } else { numericValue = 0; } } else { System.out.print("Error: The letter should be capitalized and be A, B, C, D or F only."); } if (sign.equals("+") || sign.equals("-") || sign.length()== 0) { if (sign.equals("+")) { if (letter.equals("A")) { System.out.print("The numeric value is: " + numericValue); } else { numericValue = numericValue + 0.3; System.out.print("The numeric value is: " + numericValue); } } else if (sign.equals("-")) { numericValue = numericValue - 0.3; System.out.print("The numeric value is: " + numericValue); } else { System.out.print("The numeric value is: " + numericValue); } } else { System.out.print("Error: If the grade has a sign, it should be + or - only."); } } }