Assignement: 97 Using Methods to Calculate the Area of Shapes

Code

   /// Name: Sean Harrison
    /// Period: 7
    /// Program name: AreaCalculator
    /// File Name: AreaCalculator.java
    /// Date Finished: 3/29/2016
    

import java.util.Scanner;

public class AreaCalculator
{
    public static void main( String[] args )
    {
        Scanner keyboard = new Scanner(System.in);
        
        int shape, base, height, length, width, radius, side;
        
        System.out.println("Shape Area Calculator version 3.4 (c) 2016 Harrison Inc.");
        do
        {
            System.out.println();
            System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
            System.out.println("\n1) 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: ");
                base = keyboard.nextInt();
                System.out.print("Height: ");
                height = keyboard.nextInt();
                System.out.println("\nThe area is " + areaTriangle(base, height) );
            }
            else if ( shape == 2 )
            {
                System.out.print("Length: ");
                length = keyboard.nextInt();
                System.out.print("Width: ");
                width = keyboard.nextInt();
                System.out.println("\nThe area is " + areaRectangle(length, width));
            }
            else if ( shape == 3 )
            {
                System.out.print("Side length: ");
                side = keyboard.nextInt();
                System.out.println("\nThe area is " + areaSquare(side));
            }
            else if ( shape == 4 )
            {
                System.out.print("Radius: ");
                radius = keyboard.nextInt();
                System.out.println("\nThe area is " + areaCircle(radius));
            }
            else if ( shape == 5 )
                System.out.println("Goodbye.");
        }
        while( shape != 5 );
    }
    public static double areaCircle( int radius )
    {
        double result;
        result = radius * radius;
        result = result * Math.PI;
        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 areaTriangle( int base, int height )
    {
        double result;
        result = (base * height) / 2;
        return result;
    }
}

    
 

Picture of the output

Assignment 97