-
Nov 26th, 2014, 05:29 AM
#1
Thread Starter
Junior Member
Cannot find symbol error?
The program is just a simple one to print grades using only methods.
the problem is Im trying to use a returned value in another method but the compiler keeps telling me it cannot find the symbol "mark". the problem areas are marked in blue.
Im basically trying to input a value into the keyboard and then use it in another method.
any help would be great.
public static void main(String[] args)
{
printTitle();
enterMark();
gradeCalculator(mark);
printGrade();
}
public static void printTitle()
{
System.out.println("Grade Classifier");
System.out.println("****************");
}
public static int enterMark()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter grade ");
int mark = in.nextInt();
return mark;
}
public static String gradeCalculator(int grade)
{
String gradeAchieved = "";
if(grade >= 70 && grade <= 100)
{
gradeAchieved = "Grade A Pass";
}
else if(grade >= 60 && grade <= 69)
{
gradeAchieved = "Grade B Pass";
}
else if(grade >= 50 && grade <= 59)
{
gradeAchieved = "Grade C Pass";
}
else if(grade >= 40 && grade <= 49)
{
gradeAchieved = "Grade D Pass";
}
else
{
gradeAchieved = "Grade F Fail";
}
return gradeAchieved;
}
public static void printGrade()
{
System.out.println("Congrtulations, you are awarded a ");
//Incomplete
}
-
Nov 26th, 2014, 07:01 AM
#2
Re: Cannot find symbol error?
mark is local to the enterMark function, so you can't reference it outside that function, it doesn't exist.
You're returning the value from the function, so either assign it to a variable, or use the return directly.
Code:
public static void main(String[] args)
{
printTitle();
int mark = enterMark();
gradeCalculator(mark);
printGrade();
}
// or
public static void main(String[] args)
{
printTitle();
gradeCalculator(enterMark());
printGrade();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|