Prog 97: Area Calculator
///Name: Ilana Levy
///Period: 5
///Program Name: Area Calculator
///File Name: areaCalc.java
///Date Finished: 9/29/2015
import java.util.Scanner;
public class areaCalc
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner( System.in );
int shape, radius, length, width, side, base, height;
System.out.println( "Shape Area Calculator" );
do
{
System.out.println( "\n-=-=-=-=-=-=-=-=-=-=-=-\n1) Triangle\n2) Rectangle\n3)Square\n4)Circle\n5)Quit\nWhich shape: " );
shape = keyboard.nextInt();
if ( shape == 1 )
{
System.out.print( "Base: " );
base = keyboard.nextInt();
System.out.print( "Height: " );
height = keyboard.nextInt();
System.out.println( "The area is " + triangle(base, height) );
}
else if ( shape == 2 )
{
System.out.print( "Length: " );
length = keyboard.nextInt();
System.out.print( "Width: " );
width = keyboard.nextInt();
System.out.println( "The area is " + rectangle(length, width) );
}
else if ( shape == 3 )
{ System.out.print( "Side: " );
side = keyboard.nextInt();
System.out.println( "The area is " + square(side) );
}
else if ( shape == 4 )
{ System.out.println( "Radius: " );
radius = keyboard.nextInt();
System.out.println( "The area is " + circle(radius) );
}
else
Quit();
} while ( shape != 5 );
}
public static double triangle( int base, int height )
{
double area = base * height /2;
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 Quit()
{
String quit = "Goodbye" ;
return quit;
}
}