Advertisement
Guest User

AreaCalculatorIncomplete

a guest
May 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AreaCalculator{
  4.  
  5.   public static void main(String[] args){
  6.     Scanner kb = new Scanner(System.in);
  7.    
  8.     //invoke the menu method to print the menu
  9.     //the user's int choice is returned and stored in choice
  10.     int choice = menu();
  11.    
  12.     if( choice == 1 ){
  13.       System.out.print("Base: ");
  14.       int b = kb.nextInt();
  15.       System.out.print("Height: ");
  16.       int h = kb.nextInt();
  17.       System.out.println("The area is " + areaTriangle(b,h) );
  18.     }
  19.   }
  20.  
  21.   //Method to calculate area of a Triangle
  22.   //calculation is done by .5 * b * h
  23.   public static double areaTriangle( int base, int height ){
  24.     return .5 * base * height;
  25.   }
  26.        
  27.   //Method to choose which shape to calculate the area of
  28.   //returns the user's choice as an int
  29.   public static int menu(){
  30.     Scanner kb = new Scanner(System.in);
  31.    
  32.     //Prompt the user and print his/her options
  33.     System.out.println("1) Triangle");
  34.     System.out.println("2) Rectangle");
  35.     System.out.println("3) Square");
  36.     System.out.println("4) Circle");
  37.     System.out.println("5) Quit");
  38.     System.out.print("Which shape: ");
  39.    
  40.     //get the user's int choice and return it
  41.     int choice = kb.nextInt();
  42.     return choice;
  43.   }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement