Programming Assignment #97
Code
import java.util.Scanner;
public class AreaCalculator{
public static void main(String[] args){
int input = 0;
Scanner k = new Scanner(System.in);
System.out.println("");
while(input != 5){
System.out.println("----------------------------");
System.out.println("");
System.out.println("1) Square");
System.out.println("2) Rectangle");
System.out.println("3) Triangle");
System.out.println("4) Cirlce");
System.out.println("5) Quit");
System.out.println("");
System.out.print("Which shape? ");
input = k.nextInt();
System.out.println();
double area = 0;
if(input == 1){
System.out.print("Length: ");
int l = k.nextInt();
area = l * l;
}
else if(input == 2){
System.out.print("Width: ");
int w = k.nextInt();
System.out.print("Height: ");
int h = k.nextInt();
area = w * h;
}
else if(input == 3){
System.out.print("Base: ");
int b = k.nextInt();
System.out.print("Height: ");
int h = k.nextInt();
area = 0.5 * b * h;
}
else if(input == 4){
System.out.print("Radies: ");
int r = k.nextInt();
area = 3.1415926 * r * r;
}
System.out.println();
System.out.println("The area is " + area);
System.out.println();
}
}
}
Outputs