I am trying to condense my code as much as possible, and am trying to output my variable "Grade" in the finally instead of each case statement BUT it isn't recognizing the variable. I feel like the solution for this is way too easy but i cant figure it out for the life of me. Thank you.
Code:
public class Grade {//1
public static void main(String[] args) {//2
ConsoleReader console = new ConsoleReader(System.in);
boolean done = false;
System.out.println("Enter your grade percentage:");
do{
try{
int percent = (int) console.readDouble();
Math.round(percent);
percent = (int) percent / 10;
String grade ="Input was not valid";
if(percent <= 5){//3
grade = "Your grade is an F, Work Harder so you won't have to retake!";
System.out.println(grade);
done = true;
}else{//3//4
switch (percent){//5
case 6:
grade = "Your grade is a D, work harder";
System.out.println(grade);
done = true;
break;
case 7:
grade = "Your grade is a C, That's average but you could do better.";
System.out.println(grade);
done = true;
break;
case 8:
grade = "Your grade is a B, That is pretty good but strive for that A";
System.out.println(grade);
done = true;
break;
case 9:
grade = "Your grade is a A, Good Work!!";
System.out.println(grade);
done = true;
break;
case 10:
grade = "Your grade is a A, Good Work!!";
System.out.println(grade);
done = true;
break;
default:
grade = "Your input was invalid, Please enter your grade percentage.";
System.out.println(grade);
done = false;
break;
}//5
}//4
}catch(NumberFormatException e){
System.out.println("Please input only numbers, try again:");
}finally{
if(done == true){
//ERROR System.out.println(grade); //ERROR
System.out.println("I hope you're happy with your grade!");
}else{
}
}
}while(done == false);
}//2
}//1