Assignemnt #97 Area Calculator
Code
///Name: Prooz Fereydouni
///Period: 7
///Project Name: Area Calculator
///File Name: AC.java
///Date: 3/31/2016
import java.util.Scanner;
public class AC
{
public static void main( String[] args )
{
int answer=0;
while(answer!=5)
{
Scanner kb = new Scanner(System.in);
System.out.println("Which shape do you want to find the area of? Input the corresponding number.");
System.out.println("1) Triangle");
System.out.println("2) Rectangle");
System.out.println("3) Square");
System.out.println("4) Circle");
System.out.println("5) Quit)");
answer = kb.nextInt();
if(answer==1)
{
System.out.println("Base of the triangle: ");
int a= kb.nextInt();
System.out.println("Height of the triangle: ");
int b= kb.nextInt();
int area1 = areaTriangle(a,b);
System.out.println("The area of the triangle is " + area1);
}
else if(answer==2)
{
System.out.println("Length of the rectangle: ");
int c= kb.nextInt();
System.out.println("Width of the rectangle: ");
int d= kb.nextInt();
int area2 = areaRectangle(c,d);
System.out.println("The area of the triangle is " + area2);
}
else if(answer==3)
{
System.out.println("Side of the square: ");
int e= kb.nextInt();
int area3 = areaSquare(e);
System.out.println("The area of the triangle is " + area3);
}
else if(answer==4)
{
System.out.println("Radius of the circle: ");
int f= kb.nextInt();
double area4 = areaCircle(f);
System.out.println("The area of the triangle is " + area4);
}
else if(answer!=1 && answer!=2 && answer!=3 && answer!=4 && answer!=5)
{
System.out.println("WRONG INPUT!");
answer = kb.nextInt();
}
}
}
public static double areaCircle( int radius )
{
double area = radius * radius * Math.PI;
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 int areaTriangle( int base, int height )
{
int area = base * height / 2;
return area;
}
}
Picture of the output