-4

I'm sure some of you have seen this prompt before. I'm sure there's a simple solution but I'm very new to java and need assistance.

My prompt reads:

Assume that a gallon of paint covers about 350 square feet of wall space. Create an application with a main() method that prompts the user for the length, width, and height of a rectangular room. Pass these three values to a method that does the following:

-Calculates the wall area for a room

-Passes the calculated wall area to another method that calculates and returns the number of gallons of paint needed

-Displays the number of gallons needed

-Computes the price based on a paint price of $32 per gallon, assuming that the painter can buy any fraction of a gallon of paint at the same price as a whole gallon

-Returns the price to the main() method

The main() method displays the final price. For example:

You will need 2.0 gallons

The price to paint the room is $64.0

The error(s) I get:

PaintCalculator.java:15:

error: cannot find symbol

computeGallons(area);

symbol: variable area

location: class PaintCalculator

PaintCalculator.java:16: error: cannot find symbol

computeTotalCost(gallons);

symbol: variable gallons

location: class PaintCalculator

2 errors

Here is the code producing the error:

public class PaintCalculator 
{
    public static void main (String args[]) 
    {
        System.out.println("Please enter the length, width, and height of your rectangular room.");
    Scanner input = new Scanner(System.in);
    System.out.println("Enter length >>");
    double length = input.nextDouble();
    System.out.println("Enter width >>");
    double width = input.nextDouble();
    System.out.println("Enter height >>");
    double height = input.nextDouble();
    computeArea(length, width, height);
    computeGallons(area);
    computeTotalCost(gallons);
    }

    public static double computeArea(double length, double width, double height) 
    {
        double area = (length * height * 2 + height * width * 2);
        return area;
    }
    public static double computeGallons(double area) 
    {
        double gallons = (area/350);
        System.out.println("You will need " + gallons + " gallons");
        return gallons;
    }
    public static double computeTotalCost(double gallons)
    {
        double totalCost = gallons * 32;
        System.out.println("The price to paint the room is $" + totalCost);
        return totalCost;
    }
}  





Andy
  • 61,948
  • 13
  • 68
  • 95
daiger427
  • 1
  • 1
  • 1
    `area` and `gallons` are never defined. – Sudhir Ojha Oct 20 '21 at 05:08
  • Does this answer your question? [What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?](https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-or-cannot-resolve-symbol-error-mean) – sorifiend Oct 20 '21 at 05:18

2 Answers2

2

You have to assign return value from method computeArea and computeGallons to area and gallons respectively. try changing following:

computeArea(length, width, height);
computeGallons(area);

to

double area = computeArea(length, width, height);
double gallons = computeGallons(area);
Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24
  • Nevermind, that was exactly what was needed. Can't thank you enough. I thought since they were already defined in other methods I did not need to define them again. You guys rock! – daiger427 Oct 20 '21 at 05:21
1

Look closely at your main method. You used variables area and gallons, both of which aren't defined in that scope (or at all for that matter).

dilanx
  • 113
  • 1
  • 7
  • I thought I defined them both under computeGallons and computeArea respectively. Do I need to move where I used the variables to after the methods? I'm very confused as I'm trying to get the program to print the needed gallons and cost but this prevents it, and when I take out computeGallons(area); and computeTotalCost(gallons); it does nothing but prompt the user for the length width and height and then ends. Do I need to remove the use of those variable there entirely? – daiger427 Oct 20 '21 at 05:18