Assignment #97 and Area Calculator
Code
///Name: Tim Gibson
///Period: 6
///Project Name: Area Calculator
///File Name: Area.java
///Date Finished: 11/12/15
import java.util.Scanner;
public class Area
{
public static void main ( String[] args )
{
Scanner kb = new Scanner(System.in);
int r, s, b, h, l, w, choice; //r= radius, s = square, b=base, h=height, l = length, w = width
do
{
System.out.print( "\n1) Triangle \n2) Rectangle \n3) Square \n4) Circle \n5) Quit \nWhich shape: " );
choice = kb.nextInt();
System.out.println();
if ( choice == 1 )
{
System.out.print( "Base: " );
b = kb.nextInt();
System.out.print( "Height: " );
h = kb.nextInt();
System.out.println( "\nThe area is " + areaTriangle(b,h) + "." );
}
else if ( choice == 2 )
{
System.out.print( "Length: " );
l = kb.nextInt();
System.out.print( "Width: " );
w = kb.nextInt();
System.out.println( "\nThe area is " + areaRectangle(l,w) + "." );
}
else if ( choice == 3 )
{
System.out.print( "Side length: " );
s = kb.nextInt();
System.out.println( "\nThe area is " + areaSquare(s) + "." );
}
else if ( choice == 4 )
{
System.out.print( "Radius: " );
r = kb.nextInt();
System.out.println( "\nThe area is " + areaCircle(r) + "." );
}
else if ( choice == 5 )
System.out.println( "\nGoodbye" );
else
System.out.print( "\nerror" );
} while ( choice != 5 );
}
public static double areaCircle( int r )
{
double A;
A = Math.PI * r * r;
return A;
}
public static int areaSquare( int s )
{
int A = s * s;
return A;
}
public static int areaRectangle( int l, int w )
{
int A = w * l;
return A;
}
public static double areaTriangle ( int b, int h )
{
double A;
A = 0.5 * b * h;
return A;
}
}
Picture of the output