Assignemnt #97 and Area Calculator
Code
/// Name: David Shkolnikov
/// Period: 6
/// Program Name: Area Calculator
/// File Name: AreaCalculator.java
/// Date Finished: 3/28/2016
import java.util.Scanner;
public class AreaCalculator
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int shape, base, height, length, width, radius, side;
System.out.println("Shape Area Calculator version 1.0 (c) 2016 Shkolnikov Inc.");
do
{
System.out.println("\n-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
System.out.println("\n1) 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();
System.out.println();
if ( shape == 1 )
{
System.out.print("Base: ");
base = keyboard.nextInt();
System.out.print("Height: ");
height = keyboard.nextInt();
System.out.println("\nThe area is " + areaTriangle(base, height) );
}
else if ( shape == 2 )
{
System.out.print("Length: ");
length = keyboard.nextInt();
System.out.print("Width: ");
width = keyboard.nextInt();
System.out.println("\nThe area is " + areaRectangle(length, width));
}
else if ( shape == 3 )
{
System.out.print("Side length: ");
side = keyboard.nextInt();
System.out.println("\nThe area is " + areaSquare(side));
}
else if ( shape == 4 )
{
System.out.print("Radius: ");
radius = keyboard.nextInt();
System.out.println("\nThe area is " + areaCircle(radius));
}
else if ( shape == 5 )
System.out.println("Goodbye.");
}
while( shape != 5 );
}
public static double areaCircle( int radius )
{
double result;
result = radius * radius;
result = result * Math.PI;
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 areaTriangle( int base, int height )
{
double result;
result = (base * height) / 2;
return result;
}
}
Picture of the output