This question already has an answer here:
I am receiving an error "cannot find symbol". Here is the relevant portion of my main
method, where I am receiving the error:
public static void main (String[] args) {
printBACResults(drinksConsumed, timeElapsed, maleBAC, femaleBAC, isImpaired);
}
Here is the method where I define and use the variable:
public static void printBACResults(int drinksConsumed, int timeElapsed, double maleBAC, double femaleBAC, boolean isImpaired) {
System.out.println();
System.out.println();
System.out.println();
System.out.println("After consuming " + drinksConsumed +
" drinks within "
+ timeElapsed + " hour(s):");
System.out.printf("\tCurrent BAC for a male will be approximately: %.3f\n", maleBAC);
System.out.printf ("\tCurrent BAC for a female will be approximately: %.3f\n", femaleBAC);
if (maleBAC >= 0.08)
isImpaired = true;
else
isImpaired = false;
if (isImpaired)
System.out.println("This driver is legally impaired.");
else
System.out.println("This driver is not legally impaired.");
}
NetBeans tells me that my variable isImpaired
cannot be found, but I can't find a relevant way to declare it so that it can be read by both my main
method and printBACResults
method.
Aucun commentaire:
Enregistrer un commentaire