[/import java.util.Scanner;
import static java.lang.Math.*;
/**
This program demonstrates static methods
*/
public class Geometry
{
// define the private printMenu method with no parameters and doesn't return anything
public static void printMenu()
{
System.
out.
println ("Choose what you woud like to calculate");
System.
out.
println ("1. Find the are of a circle");
System.
out.
println ("2. Find the area of a rectangle");
System.
out.
println ("3. Find the area of a triangle");
System.
out.
println ("4. Find the circumference of a circle");
System.
out.
println ("5. Find the perimeter of a rectangle");
System.
out.
println ("6. Find the perimeter of a triangle");
System.
out.
println ("Enter the number of your choice: ");
}
public static void main
(String [] args
) {
System.
out.
println("This is a geometry calculator");
int choice; //the user's choice
double value = 0; //the value returned from the method
char letter; //the Y or N from the user's decision to exit
double radius; //the radius of the circle
double area; //the area of the circle
double length; //the length of the rectangle
double width; //the width of the rectangle
double height; //the height of the triangle
double base; //the base of the triangle
double side1; //the first side of the triangle
double side2; //the second side of the triangle
double side3; //the third side of the triangle
//create a scanner object to read from the keyboard
Scanner keyboard =
new Scanner
(System.
in);
//do loop was chose to allow the menu to be displayed first
do
{
//call the printMenu method
printmenu();
choice = keyboard.nextInt();
switch (choice)
{
case 1:
System.
out.
print("Enter the radius of the circle: ");
radius = keyboard.nextDouble();
value = circleArea(radius);
/**
*The circleArea method calculates the
*@param radius
*@param area
***/
//call the circleArea method and store the result in the value variable
public static double CircleArea(double radius)
{
double area = 0;
area= (PI * (radius * radius)); //compute and return the circle's area
System.
out.
println("The area of the circle is " + value
);
}
break;
case 2:
System.
out.
print("Enter the length of the rectangle: ");
length = keyboard.nextDouble();
System.
out.
print("Enter the width of the rectangle: ");
width = keyboard.nextDouble();
//call the rectangleArea method and store the result in the value variable
public static double rectangleArea(double length, double width)
{
this.length = length;
this.width = width;
}
System.
out.
println("The area of the rectangle is " + value
);
break;
case 3:
System.
out.
print("Enter the height of the triangle: ");
height = keyboard.nextDouble();
System.
out.
print("Enter the base of the triangle: ");
base = keyboard.nextDouble();
//call the triangleArea method and store the result in the value variable
System.
out.
println("The area of the triangle is " + value
);
break;
case 4:
System.
out.
print("Enter the radius of the circle: ");
radius = keyboard.nextDouble();
//call the circumference method and store the result in the value variable
System.
out.
println("The circumference of the circle is " + value
);
break;
case 5:
System.
out.
print("Enter the length of the rectangle: ");
length = keyboard.nextDouble();
System.
out.
print("Enter the width of the rectangle: ");
width = keyboard.nextDouble();
//call the perimeter method and store the result in the value variable
System.
out.
println("The perimeter of the rectangle is " + value
);
break;
case 6:
System.
out.
print("Enter the length of side 1 of the triangle: ");
side1 = keyboard.nextDouble();
System.
out.
print("Enter the length of side 2 of the triangle: ");
side2 = keyboard.nextDouble();
System.
out.
print("Enter the length of side 3 of the triangle: ");
side3 = keyboard.nextDouble();
//call the perimeter method and store the result in the value variable
System.
out.
println("The perimeter of the triangle is " + value
);
break;
default:
System.
out.
println("You did not enter a valid choice.");
}
keyboard.nextLine(); //consumes the new line character after the number
System.
out.
println("Do you want to exit the program (Y/N)?: ");
String answer = keyboard.
nextLine();
letter = answer.charAt(0);
}while (letter != 'Y' && letter != 'y');
}
}]
--------------------Configuration: <Default>--------------------
I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:66: illegal start of expression
public static double CircleArea(double radius)
^
I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:66: illegal start of expression
public static double CircleArea(double radius)
^
I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:66: ';' expected
public static double CircleArea(double radius)
^
I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:66: '.class' expected
public static double CircleArea(double radius)
^
I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:66: ';' expected
public static double CircleArea(double radius)
^
I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:80: illegal start of expression
public static double rectangleArea(double length, double width)
^
I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:80: illegal start of expression
public static double rectangleArea(double length, double width)
^
I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:80: ';' expected
public static double rectangleArea(double length, double width)
^
I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:80: '.class' expected
public static double rectangleArea(double length, double width)
^
I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:80: ';' expected
public static double rectangleArea(double length, double width)
^
I:\CSCI 2911\CSCI 2911\CSCI TEMP\0136095089_lmsc\Lab 5\Geometry.java:80: ';' expected
public static double rectangleArea(double length, double width)
^
11 errors