Assignemnt #97

Code


import java.util.Scanner;

public class AreaCalculator 
{
    public static void main( String[] args )
    {
    
        Scanner key = new Scanner(System.in);

        
        int base, height, radius;
        int shape = 0;
        
        System.out.println("Area calculator version 0.1 (c) Newsom Inc. ");
        
        while ( shape != 5 )
        {
            
            
            System.out.println("");

            System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
            System.out.println("");

            System.out.println("Please select an option:");
            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.println("Which shape? ");
            
            shape = key.nextInt();

            
            if ( shape == 1 )
            {
                System.out.println("Base? ");
                base = key.nextInt();
                System.out.println("");

                System.out.println("Height? ");
                height = key.nextInt();
                System.out.println("");

                System.out.println("The area is " + areaTriangle(base,height));
            }
            else if ( shape == 2 )
            {
                System.out.println("Base? ");
                base = key.nextInt();
                System.out.println("");

                System.out.println("Height? ");
                height = key.nextInt();
                System.out.println("");

                System.out.println("The area is " + areaRectangle(base,height));
            }
            else if ( shape == 3 )
            {
                System.out.println("Length of one side? ");
                base = key.nextInt();


                System.out.println("The area is " + areaSquare(base));
            }
            else if ( shape == 4 )
            {
                System.out.println("Length of radius? ");
                radius = key.nextInt();

                System.out.println("The area is " + areaCircle(radius));
            }
            
            System.out.println();
            System.out.println();
            
        }
        
        System.out.println("goodbye.");
        
    }
    
    public static double areaTriangle( int base, int height )
    {
        double area = base * height * .5;
        
        return area;
    }
    
    public static int areaRectangle( int base, int height )
    {
        int area = base*height;
        
        return area;
    }
    
    public static int areaSquare( int side)
    {
        int area = side*side;
        
        return area;
    }
    
    public static double areaCircle( int radius )
    {
        double area = Math.PI * radius * radius;
        
        return area;
    }
    
    
    
}
    

Picture of the output