-3
calculateArea(Length, Height, Width);
     double area;
     calculateCost(area);
}

public static double calculateArea(int l, int h, int w) {
    //Variables
    double area;
    //Length = l;
    // Height = h;
    //Width = w;
    //Find the area
    area = l * h * w;

    //returns area outside the method
    return area; 
}

public static void calculateCost(double ar)

PaintCalculator.java:39: error: variable area might not have been initialized
      calculateCost(area);
                    ^
1 error

I can't figure out why it isn't initialized when I returned the value for area in the calculateArea method. I've tried declaring and initializing the double area; above calculateCost, but I'm stumped as to why area inside the calculateCost is set to double the area.

David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
tfulk
  • 1
  • 1

2 Answers2

1

You must assign your variable area to your function calculateArea:

  double area = calculateArea(Length, Height, Width);
  calculateCost(area);
0

the value for area is currently null, set it equal to something or use the other method you have shown to calculate the area

Suhas Bacchu
  • 37
  • 1
  • 1
  • 6