Assignment 97
import java.util.Scanner;
public class AreaCalculator
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int radius, length, width, side, base, height, menu;
System.out.println("Area Calculator");
do {
System.out.print("\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n\n1) Triangle\n2) Rectangle\n3) Square\n4) Circle\n5) Quit\n>> ");
menu = keyboard.nextInt();
System.out.println();
if (menu == 1)
{
System.out.print("Base: ");
base = keyboard.nextInt();
System.out.print("Height: ");
height = keyboard.nextInt();
System.out.println("The area is " + areaTriangle(base,height) + ".");
}
else if (menu == 2)
{
System.out.print("Length: ");
length = keyboard.nextInt();
System.out.print("Width: ");
width = keyboard.nextInt();
System.out.println("The area is " + areaRectangle(length,width) + ".");
}
else if (menu == 3)
{
System.out.print("Side length: ");
side = keyboard.nextInt();
System.out.println("The area is " + areaSquare(side) + ".");
}
else if (menu == 4)
{
System.out.print("Radius: ");
radius = keyboard.nextInt();
System.out.println("The area is " + areaCircle(radius) + ".");
}
} while (menu != 5);
}
public static double areaTriangle( int base, int height )
{
double area = base * height * .5;
return area;
}
public static int areaRectangle( int length, int width )
{
int area = length * width;
return area;
}
public static int areaSquare( int side )
{
int area = side * side;
return area;
}
public static double areaCircle( int radius )
{
double area = radius * radius * Math.PI;
return area;
}
}