Sunday, 15 September 2013

cannot find symbol java error

cannot find symbol java error

So I am used to writing in c++ and I just can't figure out these java
errors. I appreciate any help or advice. Here is my code:
import java.util.Scanner;
public class Grade
{
public int inputScore()
{
int testScore;
System.out.println("Welcome to the Letter Grade Converter");
System.out.println("Enter numberical grade:");
Scanner sc = new Scanner (System.in);
testScore =sc.nextInt();
return testScore;
}
public String assignLetter()
{
String grade;
if (testScore >= 88) {
grade = "A";
} else if (testScore >=80){
grade = "B";
} else if (testScore >=67){
grade = "C";
} else if (testScore >=60){
grade = "D";
} else if (testScore >= 0){
grade = "F";
}
return grade;
}
public String printResult()
{
System.out.println ("Letter grade:" + grade);
}
}
Along with my driver program:
public class GradeApp
{
public static void main (String[] args)
{
Grade studentGrade = new Grade(); // create student object
String choice="y";
while (choice.equalsIgnoreCase("y")) {
studentGrade.inputScore(); //get score from user and assign it to the
variable
studentGrade.assignLetter(); //assign a letter grade based on the
score
studentGrade.printResult(); //display the letter grade
}
}
}
Neither will compile. I can't seem to figure out why. Also I am used to
using the relational operator "::" in c++ which references the driver code
to the classes in the other code. I was wondering how to do that in java.
It keeps giving me a cannot find symbol error on the "grade" variable at
the very bottom as well as at all the testScore instances.

No comments:

Post a Comment