Noobs need help again.
We're dumb, we fixed our first problem only to get a new one. I'm getting an error cannot find symbol variable totalCost. How do we fix this? It is on line 53. We've commented it. What we're trying to do is get the displayTotal method to call the LunchCost method and display the total. Please point us in the right direction. Thanks for your help. You guys are awesome.
import java.text.*;
import javax.swing.JOptionPane;
publicclass Lunchoneb{
privatestaticdouble
appleCost,
appleQty,
breadCost,
breadQty,
cheeseCost,
cheeseQty,
wineCost,
wineQty;
publicstaticvoid main(String[] args){
DecimalFormat df =new DecimalFormat("#0.00");
}
Lunchoneb()
{
appleCost = 2.51;
appleQty = 2;
breadCost = 1.89;
breadQty = 2;
cheeseCost = 2.79;
cheeseQty = 1;
wineCost = 29.95;
wineQty = 2;
String yourbudgetString;
double budget;
yourbudgetString = JOptionPane.showInputDialog(null,"Enter Your Budget.","Budget", JOptionPane.INFORMATION_MESSAGE);
budget = Double.parseDouble(yourbudgetString);
}
publicstaticdouble LunchCost(double totalCost){
//double totalCost;
totalCost = (appleCost * appleQty) + (breadCost * breadQty) + (cheeseCost * cheeseQty) + (wineCost * wineQty);
return totalCost;
}
publicdouble displayTotal(){
System.out.println(totalCost);//I keep getting an error here that says cannot find symbol variable totalCost
}
//double appleCost = 2.51, appleQty = 2, breadCost = 2, breadQty = 2, cheeseCost = 2, cheeseQty = 1, wineCost = 20, wineQty = 2;
//double totalCost = (appleCost * appleQty) + (breadCost * breadQty) + (cheeseCost * cheeseQty) + (wineCost * wineQty); //Added wine since it was mentioned in class.
//double budget = 74.28;
//double expense = budget - totalCost;
//System.out.println("Price of Apples per pound: $" + df.format(appleCost));
//System.out.println("Price of Bread per loaf: $" + df.format(breadCost));
//System.out.println("Price of Cheese per pound: $" + df.format(cheeseCost));
//System.out.println("Price of Wine per bottle: $" + df.format(wineCost));
//System.out.println("Total Price of all items: $" + df.format(totalCost));
//System.out.println("Your Budget: $" + df.format(budget));
//System.out.println("You have: $" + df.format(expense));
//if (expense < 0) //If statement to determine and display whether you have exceeded your budget.
//System.out.println("You have exceeded your budget.");
//else
//System.out.println("You have not exceeded your budget.");
}

