import java.util.Scanner;
public class EP55Out
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Please enter a grade: ");
String letter = in.next();
// getNumericGrade(grade);
}
public static void getNumericGrade(double grade)
{
int spacer = 0;
String first = letter.substring(0,1);
String second = letter.substring(1,2);
if (first.equalsIgnoreCase("a"))
grade = 4.0;
else if (first.equalsIgnoreCase("b"))
grade = 3.0;
else if (first.equalsIgnoreCase("c"))
grade = 2.0;
else if (first.equalsIgnoreCase("d"))
grade = 1.0;
else if (first.equalsIgnoreCase("f"))
grade = 0;
else grade = 9;
if (second.equalsIgnoreCase("+"))
grade += 0.3;
else if (second.equalsIgnoreCase("-"))
grade -= 0.3;
else
grade += 9;
System.out.println(grade);
}
}
I don’t know if you guys understand what I mean, but I keep getting the error that “grade” does not exist even though it is defined in the main. I know it has something to do with “void” but I have no clue what. Can anybody help?
So you are learning Java don’t you?
I’ll try to explain what you are doing wrong.
You missed an important point with variables…
If you define a variable in a method – it is only visible in THE DEFINING METHOD!
So
public static void getNumericGrade(String letter)
cannot know that there is a letter variable in
public static void main(String[] args)
Hope I could help you 😉