Code no longer runs as I can't figure out how to get the scanner to run, but how do I get the methods to execute? Tips and help is appreciated. Thanks in advance.
For clarification, I want this code to run like a geometry calculator, however I do not really know how to call methods (which I think is the issue here)
import java.util.Scanner;
import java.lang.Math;
public class Geometry
{
private static void printMenu()
{
System.out.println("This is a geometry calculator");
System.out.println("Choose what you would like to calculate");
System.out.println("1. Find the area of a rectangle");
System.out.println("2. Find the perimeter of a rectangle");
System.out.println("3. Find the perimeter of a triangle");
System.out.println("Enter the number of your choice:");
}
public static void main (String [] args)
{
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 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
Scanner keyboard = new Scanner (System.in);
}
public static double rectangleArea(double length, double width, double value, Scanner keyboard) {
System.out.print("Enter the length of the rectangle: ");
length = keyboard.nextDouble();
System.out.print("Enter the width of the rectangle: ");
width = keyboard.nextDouble();
value= length*width;
System.out.println("The area of a rectangle is " + value);
return value;
}
public static double rectanglePerimeter(double length, double width, double value, Scanner keyboard) {
System.out.print("Enter the length of the rectangle: ");
length = keyboard.nextDouble();
System.out.print("Enter the width of the rectangle: ");
width = keyboard.nextDouble();
value= (2*length)+(2*width);
System.out.println("The perimeter of the rectangle is " + value);
return value;
}
public static double trianglePerimeter(double side1, double side2, double side3, double value, Scanner keyboard) {
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
value = (side1 + side2 + side3);
System.out.println("The perimeter of the triangle is " + value);
return value;
//default:
//System.out.println("You did not enter a valid choice.");
}
}