Program #97

Code

   
    /// Name: Afaf Nabeeha
    /// Period: 7
    /// Program Name: Area Calculator
    /// File Name: Area.java
    /// Date Finished: 3/8/2016 public class Area

    import java.util.Scanner;

    public class Area
    {
        public static void main(String[] args)
        {
            Scanner k = new Scanner(System.in);
            int shape;
            System.out.println("Shape Area Calculator version 1.0 (c) 2016 Nabeeha Inc.");
            do
            {
                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: ");
                shape = k.nextInt();
    
                System.out.println();
    
                if (shape == 1)
                {
                    System.out.print("Base: ");
                    int base = k.nextInt();
    
                    System.out.print("Height: ");
                    int height = k.nextInt();
    
                    System.out.println();
    
                    System.out.println("The area is " + areaT( base, height ) + ".");
                }
    
                else if (shape == 2)
                {
                    System.out.print("Length: ");
                    int length = k.nextInt();
    
                    System.out.print("Width: ");
                    int width = k.nextInt();
    
                    System.out.println();
    
                    System.out.println("The area is " + areaR( length, width ) + ".");
                }
    
                else if (shape == 3)
                {
                    System.out.print("Side length: ");
                    int side = k.nextInt();
    
                    System.out.println();
    
                    System.out.println("The area is " + areaS( side ) + ".");
                }
    
                else if (shape == 4)
                {
                    System.out.print("Radius: ");
                    int radius = k.nextInt();
    
                    System.out.println();
    
                    System.out.println("The area is " + areaC( radius ) + ".");
                }
    
                else if (shape == 5)
                {
                    System.out.println("Goodbye.");
                }
                
                else
                    System.out.println("Error. Please select a number from the list of shapes.");
                
            } while (shape != 5);
        }
        
        public static double areaC( int radius )
        {
            double a;
            a = Math.PI * radius * radius;
            return a;
        }
        
        public static int areaR( int length, int width )
        {
            int a;
            a = length * width;
            return a;
        }
        
        public static int areaS( int side )
        {
            int a;
            a = side * side;
            return a;
        }
        
        public static double areaT( int base, int height )
        {
            double a;
            a = .5 * base * height;
            return a;
        }
        
    }
             
    

Picture of the output

Assignment 97