Program 97, Area Calculator
Code
///Name: Stella Koliavas
///Period: 5
///File Name: Area.java
///Date Finshed: 3/25/16
import java.util.Scanner;
public class Area
{
public static void main( String[] args )
{
Scanner siri = new Scanner(System.in);
int shape = 1, base, height, radius, length, width, area;
while ( shape != 5 )
{
System.out.println("Shape Area Calculator");
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.println(" ");
System.out.print("> ");
shape = siri.nextInt();
if ( shape == 1 )
{
System.out.print("Base: ");
base = siri.nextInt();
System.out.println("Height: ");
height = siri.nextInt();
System.out.println("The area is " + areaTriangle(base, height));
}
if ( shape == 2 )
{
System.out.print("Length: ");
length = siri.nextInt();
System.out.print("Width: ");
width = siri.nextInt();
System.out.println("The area is " + areaRectangle(length, width));
}
if ( shape == 3 )
{
System.out.print("Length: ");
length = siri.nextInt();
System.out.println("The area is " + areaSquare(length ));
}
if ( shape == 4 )
{
System.out.print("Radius: ");
radius = siri.nextInt();
System.out.println("The area is " + areaCircle(radius));
}
if ( shape == 5 )
{
System.out.println("Thanks for playing!");
shape = 5;
}
}
}
public static double areaCircle(int radius )
{
double area = (3.14*radius*radius);
return area;
}
public static int areaRectangle(int length, int width )
{
int area = (length * width);
return area;
}
public static int areaSquare(int length )
{
int area = (length*length);
return area;
}
public static double areaTriangle(int base, int height )
{
double area = (.5* base * height);
return area;
}
}
Picture of the output