Assignment #97
Code
/*
jack newsom
period 5
program AreaCalculator
filename AreaCalculator.java
date completed 11/2/2015
*/
import java.util.Scanner;
public class AreaCalculator
{
public static void main( String[] args )
{
Scanner bot = new Scanner(System.in);
int base, height, radius;
int shape = 0;
System.out.println("Area calculator version 0.1 (c) Newsom Inc. ");
while ( shape != 5 )
{
System.out.println("");
System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
System.out.println("");
System.out.println("Please select an option:");
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.println();
System.out.println("Which shape? ");
shape = bot.nextInt();
if ( shape == 1 )
{
System.out.println("Base? ");
base = bot.nextInt();
System.out.println("");
System.out.println("Height? ");
height = bot.nextInt();
System.out.println("");
System.out.println("The area is " + areaTriangle(base,height));
}
else if ( shape == 2 )
{
System.out.println("Base? ");
base = bot.nextInt();
System.out.println("");
System.out.println("Height? ");
height = bot.nextInt();
System.out.println("");
System.out.println("The area is " + areaRectangle(base,height));
}
else if ( shape == 3 )
{
System.out.println("Length of one side? ");
base = bot.nextInt();
height = base;
System.out.println("The area is " + areaRectangle(base,height));
}
else if ( shape == 4 )
{
System.out.println("Length of radius? ");
radius = bot.nextInt();
System.out.println("The area is " + areaCircle(radius));
}
System.out.println();
System.out.println();
}
System.out.println("goodbye.");
}
public static int areaRectangle( int base, int height )
{
int area = base*height;
return area;
}
public static double areaCircle( int radius )
{
double area = Math.PI * radius * radius;
return area;
}
public static double areaTriangle( int base, int height )
{
double area = base * height * .5;
return area;
}
}
Picture of the output