symbol: variable circleArea location: class Geometry Geometry.java:114: error: cannot find symbol printArea(rectangleArea); //prints rectangle's area if the choice is #2 ^ symbol: variable rectangleArea location: class Geometry Geometry.java:119: error: cannot find symbol printArea(triangleArea); //prints traingle's area if the choice is #3 ^ symbol: variable triangleArea location: class Geometry 4 errors
public class Geometry
{
public static void main(String[] args)
{
//asks for user's choice
Scanner in = new Scanner(System.in);
displayMenu();
selectOption(choice);
System.out.println("Enter your choice (1-3): ");
int choice1 = in.nextInt();
System.out.println("Thanks for using the Geometry Calculator - Goodbye!");
//Prints if input is a number that is not one of the choices
while(choice1 < 1 || choice1 > 3 )
{
System.out.println("Invalid choice. Please enter 1 - 3: ");
choice1 = in.nextInt();
}
}
/**
Displays the menu
*/
public static void displayMenu()
{
System.out.println("Welcome to the Geometry Calculator Application");
System.out.println("1. Calculate the Area of a Circle");
System.out.println("2. Calculate the Area of a Rectangle");
System.out.println("3. Calculate the Area of a Triangle");
}
/**
This method calculates the area of the circle
@return the area of the circle
*/
public static double circle()// calculates the area of the circle
{
Scanner in = new Scanner(System.in);
System.out.println("What is the circle's radius? ");
double radius = in.nextDouble();
double circleArea = Math.PI * radius * radius;
return circleArea;
}
/**
This method calculates the area of rectangle
@result the area of the rectangle
*/
public static double rectangle()// calculates the area of the rectangle
{
Scanner in = new Scanner(System.in);
System.out.println("What is the rectangle's length? ");
double length = in.nextDouble();
System.out.println("What is the rectangle's width? ");
double width = in.nextDouble();
double rectangleArea = length * width;
return rectangleArea;
}
//calculates the area of a triangle
/**
This method calculates the area of a triangle
@return the area of the triangle
*/
public static double triangle()
{
Scanner in = new Scanner(System.in);
System.out.println("What is the length of the triangle's base? ");
double base = in.nextDouble();
System.out.println("What is the triangle's height? ");
double height = in.nextDouble();
double triangleArea = 0.5 * base * height;
return triangleArea;
}
//prints area to two decimal places
/**
This method prints the area
@param the area's value
*/
public static void printArea(double a)
{
System.out.printf("The area is "+ "%.2f" + a);
}
//assigns each choice to a method
/**
This method assigns each choice to an area method
@param choice of the method
*/
public static void selectOption(int choice)
{
if(choice==1)
{
circle();
printArea(circleArea()); //prints circle's area if the choice is #1
}
else if(choice==2)
{
rectangle();
printArea(rectangleArea); //prints rectangle's area if the choice is #2
}
else if(choice==3)
{
triangle();
printArea(triangleArea); //prints triangle's area if the choice is #3
}
}
}
This is my code for calculating the area.
These are the errors I get.
Geometry.java:17: error: cannot find symbol
selectOption(choice);
^
symbol: variable choice
location: class Geometry
Geometry.java:109: error: cannot find symbol
printArea(circleArea); //prints circle's area if the choice is #1
^
symbol: variable circleArea
location: class Geometry
Geometry.java:114: error: cannot find symbol
printArea(rectangleArea); //prints rectangle's area if the choice is #2
^
symbol: variable rectangleArea
location: class Geometry
Geometry.java:119: error: cannot find symbol
printArea(triangleArea); //prints traingle's area if the choice is #3
^
symbol: variable triangleArea
location: class Geometry
4 errors
I would appreciate help in this!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps