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