Advertisement
trentc98

Untitled

Aug 29th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class AreaFinder
  3. {
  4.     public static void main (String [] args)
  5.     {
  6.         int count = 1;
  7.         String exit = "yes";
  8.         do
  9.         {
  10.             System.out.println("To find area of rectangle, press r.\nTo find area of triangle, press t.\nTo find area of circle, press c.");   
  11.             Scanner in = new Scanner (System.in);
  12.             String userinput = in.nextLine();
  13.            
  14.             if(userinput.equals("c"))
  15.             {
  16.                 System.out.println("\nPlease type the radius.");
  17.                 double radius;
  18.                 radius = in.nextDouble ();
  19.                 double areaC = (radius*radius)*Math.PI;
  20.                 System.out.println("\nThe area of a circle with radius " + radius + " is: \n" + areaC);
  21.             }
  22.            
  23.             else if(userinput.equals("r"))
  24.             {
  25.                 System.out.println("\nPlease type length and width as l w.");
  26.                 double length, width;
  27.                 length = in.nextDouble ();
  28.                 width = in.nextDouble ();
  29.                 double areaR = (length*width);
  30.                 System.out.println("\nThe area of a rectangle with length:" + length + " and width:" + width + " is: \n" + areaR);
  31.             }
  32.            
  33.             else if(userinput.equals("t"))
  34.             {
  35.                 System.out.println("\nPlease type base and height as b h.");
  36.                 double base, height;
  37.                 base = in.nextDouble ();
  38.                 height = in.nextDouble ();
  39.                 double areaT = (base*height)/2;
  40.                 System.out.println("\nThe area of a triangle with base:" + base + " and height:" + height + " is: \n" + areaT);
  41.             }
  42.            
  43.             else
  44.             {
  45.                 System.out.println("Please type r t or c dummy.");
  46.             }
  47.    
  48.            
  49.             System.out.println("Would you like to do another problem(yes/no)");
  50.             exit = in.next();
  51.             //Program will preform as long as exit is "yes"
  52.         }
  53.         while (exit.contains("yes"));
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement