Assignment #97 and Area Calculator
Code
/// Name: Graham Pollock
/// Period: 5
/// Program Name: Area Calculator
/// File Name: AreaCalculator.java
/// Date Finished: 03/23/2016/
import java.util.Scanner;
public class AreaCalculator
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
System.out.println("Shape Area Calculator!");
System.out.println("");
System.out.println("-_-_-_-_-_-_-_-_-_-_-_");
System.out.println("");
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("Choose a shape: ");
int choice = kb.nextInt();
System.out.println("");
while (choice != 5)
{
if (choice == 1)
{
System.out.print("Base: ");
int base = kb.nextInt();
System.out.print("Height: ");
int height = kb.nextInt();
System.out.println("");
System.out.println("The area is " + areaTriangle(base, height));
System.out.println("");
}
else if (choice == 2)
{
System.out.print("Length: ");
int length = kb.nextInt();
System.out.print("Width: ");
int width = kb.nextInt();
System.out.println("");
System.out.println("The area is " + areaRectangle(length, width));
System.out.println("");
}
else if (choice == 3)
{
System.out.print("Side Length: ");
int side = kb.nextInt();
System.out.println("");
System.out.println("The area is " + areaSquare(side));
System.out.println("");
}
else if (choice == 4)
{
System.out.print("Radius: ");
int radius = kb.nextInt();
System.out.println("");
System.out.println("The area is " + areaCircle(radius));
System.out.println("");
}
else
System.out.println("ERROR");
System.out.println("-_-_-_-_-_-_-_-_-_-_-_");
System.out.println("");
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("Choose a shape: ");
choice = kb.nextInt();
System.out.println("");
}
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.14159265 * (radius * radius);
return result;
}
}
Picture of the output