Kladdy

AreaCalc

Jan 11th, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class AreaCalculator {
  3.    
  4.     static Scanner sc = new Scanner(System.in);
  5.     public static void main(String[] args)
  6.    
  7.    
  8.  
  9.     {
  10.        
  11.         System.out.println("Do you want to calculate the area of a square, rectangle, circle or triangle?");
  12.         double square;
  13.         double triangle;
  14.         double rectangle;
  15.         double circle;
  16.         String input = sc.nextLine();
  17.        
  18.    
  19.        
  20.        
  21.    
  22.  
  23.         if ("triangle".equals(input.toLowerCase()))
  24.         {
  25.             double base;
  26.             double height;
  27.             System.out.print("Enter the triangles base: ");
  28.             base = sc.nextDouble();
  29.             System.out.print("Enter the triangle's height: ");
  30.             height = sc.nextDouble();
  31.             double Area = (base * height) / 2;
  32.             System.out.println("The area of your triangle is: " + Area);
  33.         }
  34.        
  35.         if ("square".equals(input.toLowerCase()))
  36.         {
  37.             double sides;
  38.         System.out.print("Enter the lenght of the square's side: ");
  39.         sides = sc.nextDouble();
  40.         double Area = sides * sides;
  41.         System.out.println("The area of your square is: " + Area);
  42.         }
  43.        
  44.         if ("rectangle".equals(input.toLowerCase()))
  45.         {
  46.             double base;
  47.         double height;
  48.         System.out.print("Enter the rectangle's base: ");
  49.         base = sc.nextDouble();
  50.         System.out.print("Enter the rectangle's height: ");
  51.         height = sc.nextDouble();
  52.         double Area = base * height;
  53.         System.out.println("The area of your rectangle is: " + Area);
  54.         }
  55.        
  56.         if ("circle".equals(input.toLowerCase()))
  57.         {
  58.             double radius;
  59.         System.out.print("Please note: This calculator uses 10 decimals of Pi.\nEnter the circle's radius: ");
  60.         radius = sc.nextDouble();
  61.         double Area = 3.1415926535 * radius * radius;
  62.         System.out.println("The area of your circle is: " + Area);
  63.         }
  64.        
  65.         else
  66.         {
  67.             System.out.println("Oops! Looks like you spelled something wrong!");
  68.         }
  69.        
  70.    
  71.    
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment