variable might not have been initialized??
807601May 11 2008 — edited May 12 2008I'm still learning Java, so be easy on me :) The book I'm using to teach me wants me to make a program that allows you to input a students name and score. Then the program will give an output of the persons name and assign them a letter grade for the score.
here is what i came up with:
import javax.swing.*;
import java.util.*;
public class gradehelper
{
public static void main(String[] args)
{
String name;
char grade;
name = JOptionPane.showInputDialog("Enter name: ");
String n1String;
n1String = JOptionPane.showInputDialog("Enter your score:");
int score;
score = Integer.parseInt(n1String);
if (score >= 90)
grade = 'A';
else if (score >= 80)
grade = 'B';
else if (score >= 70)
grade = 'C';
else if (score >= 60)
grade = 'D';
else if (score < 60)
grade = 'F';
else
System.out.println("Invalid Score");
System.out.println("Student: " + name);
System.out.println("Grade: " + grade);
System.exit(0);
}
}
I'm sure this looks sloppy, but I am trying really hard! I keep getting 'variable grade might not have been initialized' for line 34.
Any tips?