Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable Error

Status
Not open for further replies.

Tahoe

Programmer
Sep 24, 2002
4
US
In trying to calculate a "cost" based on the area size, am getting a variable error after calling the calculate area method...any ideas on what is wrong here?

/**
* Method to calculate the area of the lawn
*/
public double calculateArea()
{
double area = 0;
area = lawnLength*lawnWidth;
return area;
}

/**
* Calculates the season charge based on the size of the lawn
*/
public String calculateCost()
{

calculateArea();

if(area < 400)
cost = 25*NUM_OF_WEEKS;
if(area > 400 || area < 600)
cost = 35*NUM_OF_WEEKS;
else
cost = 50*NUM_OF_WEEKS;
}

Thanks in advance!
 
&quot;area&quot; and &quot;cost&quot; are not defined in your &quot;calculateCost()&quot; method. Are they defined in your class? [ The &quot;area&quot; variable in your &quot;calculateArea()&quot; method is not the same as in your &quot;calculateCost()&quot; method ].

You should store the return variable of your call to calculateArea()

double area = calculateArea();
 
Thank you - I tried it - it worked!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top