Assignemnt #97 Area Calculator
Code
///Name: Morgan Kaplan
///Period: 5
///Project Name: Area Calculator
///File Name: Area.java
import java.util.Scanner;
public class Area
{
public static void main( String[] args)
{
Scanner momo=new Scanner(System.in);
int shape, Base, Height, length, width, radius, side;
do
{
System.out.println("1) Triangle, 2) Rectangle, 3) Square, 4) Circle, 5) Quit. Which shape?");
shape=momo.nextInt();
if ( shape==1 )
{
System.out.println("Base:");
Base=momo.nextInt();
System.out.println("Height:");
Height=momo.nextInt();
System.out.println("The area is " + Triangle(Base, Height) + ".");
}
else if ( shape==2 )
{
System.out.println("length:");
length=momo.nextInt();
System.out.println("width:");
width=momo.nextInt();
System.out.println("The area is " + Rectangle(length, width) + ".");
}
else if ( shape==3 )
{
System.out.println("side:");
side=momo.nextInt();
System.out.println("The area is " + Square(side) + ".");
}
else if ( shape==4 )
{
System.out.println("radius:");
radius=momo.nextInt();
System.out.println("The area is " + Circle(radius) + ".");
}
else
bye();
} while( shape!=5);
}
public static double Triangle( int Base, int Height )
{
double area=((.5)*Base*Height);
return area;
}
public static int Rectangle( int length, int width )
{
int area=(length*width);
return area;
}
public static int Square( int side )
{
int area=(side*side);
return area;
}
public static double Circle( int radius )
{
double area=(Math.PI*radius*radius);
return area;
}
public static String bye()
{
String bye= "bye";
return bye;
}
}
Picture of Output