Assignment #97 and Area Calculator
Code
//Name: Mark Katz
///Period: 6
///Program Name: Area Calculator
///File Name: area.java
///Date Finished: 1/5/16
import java.util.Scanner;
public class area
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.println( "1) Traingle ");
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: ");
int shape = keyboard.nextInt();
System.out.print( "" );
while ( shape != 5 )
{
//triangle
if ( shape == 1 )
{
System.out.print( "Base: " );
int base = keyboard.nextInt();
System.out.print( "Height: ");
int height = keyboard.nextInt();
System.out.println("");
System.out.println("The area is " + areaTriangle(base, height));
System.out.println("");
}
//rectangle
else if ( shape == 2 )
{
System.out.println( "Length: " );
int length = keyboard.nextInt();
System.out.println( "Width: " );
int width = keyboard.nextInt();
System.out.println("");
System.out.println("The area is " + areaRectangle(length, width));
System.out.println("");
}
//square
else if ( shape == 3 )
{
System.out.println( "Side length: ");
int side = keyboard.nextInt();
System.out.println("");
System.out.println("The area is " + areaSquare(side));
System.out.println("");
}
//circle
else if ( shape == 4)
{
System.out.println( "Radius: " );
int radius = keyboard.nextInt();
System.out.println("");
System.out.println("The area is " + areaCircle(radius));
System.out.println("");
}
else
System.out.println( "ERROR" );
System.out.println( "1) Traingle ");
System.out.println( "2) Rectangle " );
System.out.println( "3) Square " );
System.out.println( "4) Circle " );
System.out.println( "5) Quit ");
System.out.println( "Which shape?");
}
System.out.println( "Goodbye");
}
public static double areaTriangle( int base, int height)
{
double result;
result = (base * height) / 2 ;
return result;
}
public static int areaRectangle( int length, int width )
{
int result;
result= length * width;
return result;
}
public static int areaSquare( int side )
{
int result;
result= side * side;
return result;
}
public static double areaCircle( int radius )
{
double result;
result= 3.14159265359 * ( radius * radius );
return result;
}
}
Picture of the output