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.");

}

[4257 byte] By [kevcavea] at [2007-11-26 18:14:20]
# 1
You're definintg it as a double in a limited scope. Move the definition up so that all uses of the variable can see the definition.
ChuckBinga at 2007-7-9 5:47:42 > top of Java-index,Java Essentials,New To Java...
# 2
you never declared total cost-Bz
Bz_Unknowna at 2007-7-9 5:47:42 > top of Java-index,Java Essentials,New To Java...
# 3
Uuuhhh not really sure how to do that. I'm in my second week of object oriented programming. Could you expound upon this further. Thank you very much for your help.
kevcavea at 2007-7-9 5:47:42 > top of Java-index,Java Essentials,New To Java...
# 4
Your LunchCost method returns the total cost so you might want to do this:System.out.println(LunchCost());and get rid of the parameter.
floundera at 2007-7-9 5:47:42 > top of Java-index,Java Essentials,New To Java...
# 5
we started as dumb then we learn.
G_Abubakra at 2007-7-9 5:47:42 > top of Java-index,Java Essentials,New To Java...