#97

Code

  /// Name: Josh Bautista
  /// Period: 6
  /// Program Name: Area Calculator
  /// File Name: AC.java
  /// Date Finished: 2/26/2015
  
  import java.util.Scanner;
    
    public class AC
    {
    	public static void main( String[] args )
    	{
            Scanner keyboard = new Scanner(System.in);
            
            int radius, length, width, side, shape, base, height;
            
            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: " );
            shape = keyboard.nextInt();
            
            while ( shape != 5 )
            {
                System.out.println();
                
                if ( shape == 1 )
                {
                    System.out.print( "Base: " );
                    base = keyboard.nextInt();
                    System.out.print( "Height : " );
                    height = keyboard.nextInt();
                    System.out.println();
                    System.out.println( "The 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();
                    System.out.println( "The area is " + areaRectangle( length, width ) + "." );
                }
                
                else if ( shape == 3 )
                {
                    System.out.print( "Side: " );
                    side = keyboard.nextInt();
                    System.out.println();
                    System.out.println( "The area is " + areaSquare( side ) + "." );
                }
                
                else if ( shape == 4 )
                {
                    System.out.print( "Radius: " );
                    radius = keyboard.nextInt();
                    System.out.println();
                    System.out.println( "The area is " + areaCircle( radius ) + "." );
                }
                
                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: " );
                shape = keyboard.nextInt(); 
            }
            
            System.out.println();
            System.out.println( "Goodbye." );
            System.out.println();
        }
        
        public static double areaCircle( int radius )
        {
            double ac;
            ac = Math.PI*(radius*radius);
            return ac;
        }
        
        public static int areaRectangle( int length, int width )
        {
            int ar;
            ar = length*width;
            return ar;
        }
        
        public static int areaSquare( int side )
        {
            int as;
            as = side*side;
            return as;
        }
        
        public static double areaTriangle( int base, int height )
        {
            double at;
            at = (base*height)/2.0;
            return at;
        }
    }
    

Picture of the output

Assignment 4