Assignemnt #100
Code
/// Name: Connor Siri
/// Period: 7
/// Program Name: AreaC
/// File Name: AreaC.java
/// Date Finished: 2/8/2016
import java.util.Scanner;
public class AreaC
{
public static void main( String[] args )
{
int shape = 0;
while ( shape != 5 )
{
Scanner keyboard = new Scanner(System.in);
System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\r");
System.out.println("Area of shapes");
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();
if ( shape == 1 )
{
System.out.print("Base: ");
int base = keyboard.nextInt();
System.out.print("Height: ");
int height = keyboard.nextInt();
System.out.println("The area is " + areaTriangle(base,height));
System.out.println("");
}
else if (shape == 2)
{
System.out.print("Length: ");
int length = keyboard.nextInt();
System.out.print("Width: ");
int width = keyboard.nextInt();
System.out.println("The area is " + areaRectangle(length,width));
System.out.println("");
}
else if (shape == 3)
{
System.out.print("Side");
int side = keyboard.nextInt();
System.out.println("The area is "+ areaSquare(side));
System.out.println("");
}
else if (shape == 4)
{
System.out.print("\rRadius: ");
int radius = keyboard.nextInt();
System.out.println("\rThe area is " + areaCircle(radius));
System.out.println("");
}
else
{
System.out.println("ERROR");
System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\r");
System.out.println("Area of shapes");
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("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