Methods #97 (Getting better..)

Code

/// Name: Amir Salehi
/// Period: 7
/// Program Name:Area Calculator
/// File Name:AreaCalculator.java
/// Date Finished: 3/24/2016

    
    import java.util.Scanner;
    
    public class AreaCalculator
    {
    	public static void main( String[] args )
    	{
    		Scanner keyboard = new Scanner(System.in);
    int shape;
    		System.out.println("Shape Area Calculator version 0.1 (c) 2015 Davis Inc.");
    		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:");
                shape = keyboard.nextInt();
                double area = Forumula (shape); //REMEMBER THIS
    		System.out.println();
                System.out.println(area);

    

        } while (shape != 5 );
            System.out.println("Goodbye");
    }
        public static double Forumula( int shape )
        {
                		Scanner keyboard = new Scanner(System.in);
            double result;
            
            if ( shape == 1 ){
        System.out.print("Base:");
    int Base = keyboard.nextInt();
    System.out.print("Height:");
    int Height = keyboard.nextInt();
    result = 0.5 * Base * Height;
            }
            else if ( shape == 2 ){
             System.out.print("Length:");  
                 int Length = keyboard.nextInt();
                System.out.print("Width:");
                    int Width = keyboard.nextInt();
                result = Length * Width;
            }
                
            else if ( shape == 3 ){
                System.out.print("Side Length:");
                    int Side = keyboard.nextInt();
                    result = Side*Side;
            }
            else if ( shape == 4 ){
                System.out.print("Radius:");
                    int Radius = keyboard.nextInt();
                result = Math.PI*(Radius*Radius);
            }
        
            else 
                result = 0;
                
            return result;
        }
        
    }





    

Picture(s) of the output

Assignment 7

Back to Homepage