Assignment #97 and Area Calculator
Code
/// Name: Ali Kurland
/// Period: 6
/// Program Name: Area Calculator
/// File Name: AreaCalculator.java
/// Date Finished: 11/19/2015
import java.util.Scanner;
public class AreaCalculator
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int shape;
System.out.println( "Ali's Shape Area Calculator\n" );
System.out.println( "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n" );
do
{
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" );
System.out.print( "Which shape: " );
shape = keyboard.nextInt();
if ( shape == 1 )
{
System.out.print( "\nBase: " );
int base = keyboard.nextInt();
System.out.print( "Height: " );
int height = keyboard.nextInt();
System.out.println( "\nThe area is " + areaTriangle(base,height) + "." );
System.out.println( "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n" );
}
else if ( shape == 2 )
{
System.out.print( "\nLength: " );
int length = keyboard.nextInt();
System.out.print( "Width: " );
int width = keyboard.nextInt();
System.out.println( "\nThe area is " + areaRectangle(length,width) + "." );
System.out.println( "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n" );
}
else if ( shape == 3 )
{
System.out.print( "\nSide length: " );
int side = keyboard.nextInt();
System.out.print( "\nThe area is " + areaSquare(side) + "." );
System.out.println( "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n" );
}
else if ( shape == 4 )
{
System.out.print( "\nRadius: " );
int radius = keyboard.nextInt();
System.out.println( "\nThe area is " + areaCircle(radius) + "." );
System.out.println( "\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n" );
}
else if ( shape == 5 )
{
System.out.println( "\nGoodbye." );
}
} while ( shape < 5 );
}
public static double areaTriangle( int base, int height )
{
double A = ( base * height ) / 2;
return A;
}
public static int areaRectangle( int length, int width )
{
int A = length * width;
return A;
}
public static int areaSquare( int side )
{
int A = side * side;
return A;
}
public static double areaCircle( int radius )
{
double A = Math.PI * Math.pow(radius, 2);
return A;
}
}
Picture of the output