Assignemnt #97 and Area Calculator
Code
/// Name: Kyle Ivy
/// Period: 5
/// Program Name: AreaCalc
/// File Name: AreaCalc.java
/// Date Finished: 4/20/2016
import java.util.Scanner;
public class AreaCalc
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int choice;
System.out.println("Shape Area Calculator version 1 " );
do
{
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("Which Shape: ");
choice = keyboard.nextInt();
System.out.println();
if ( choice == 1 ){
System.out.print("Base: ");
int base = keyboard.nextInt();
System.out.print("Height: ");
int height = keyboard.nextInt();
System.out.println();
System.out.println("The area of the triangle is " + triangleArea( base, height ) + "." );
}
else if (choice == 2){
System.out.print("Base: ");
int base = keyboard.nextInt();
System.out.print("Height: ");
int height = keyboard.nextInt();
System.out.println();
System.out.println("The area of the rectangle is " + rectangleArea( base, height ) + "." );
}
else if (choice == 3){
System.out.print("Side length: ");
int length = keyboard.nextInt();
System.out.println();
System.out.println("The area of the square is " + squareArea( length ) + "." );
}
else if (choice == 4){
System.out.print("Radius: ");
int radius = keyboard.nextInt();
System.out.println();
System.out.println("The area of the circle is " + circleArea( radius ) + "." );
}
}while( choice != 5 );
System.out.println("Goodbye");
}
public static double triangleArea( int base, int height )
{
double result;
result = (base*height)/2.0;
return result;
}
public static int rectangleArea( int base, int height )
{
int result;
result = base*height;
return result;
}
public static int squareArea( int length )
{
int result;
result = length*length;
return result;
}
public static double circleArea( int radius )
{
double result;
result = Math.PI*(radius*radius);
return result;
}
}
prog97.PNG