Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /******************************************************************************
- * Author: Junaid
- * Date: 17/9/19
- * Purpose: Shape Calculator
- ******************************************************************************/
- public class ShapeCalculator
- {
- public static void main( String [] args)
- {
- Scanner sc = new Scanner(System.in);
- char userSelection;
- System.out.println("Make a selection");
- System.out.println("Type 'c' for area of circle");
- System.out.println("Type 'r' for area of rectangle");
- System.out.println("Type 't' for area of triangle");
- System.out.println("Type 'e' to exit");
- userSelection= sc.next().charAt(0);
- switch(userSelection)
- {
- case 'c':
- int diameter; int meters; int cm;
- double area; double mm; double length; double width; double base; double height; double radius;
- System.out.println("Please enter the diameter of the circle in cm");
- diameter = sc.nextInt();
- radius = (double)diameter/2;
- area = Math.PI*radius*radius;
- meters = (int)area/10000;
- cm = (int)area%10000;
- mm = (int)(area*10000%10000);
- mm = mm/100;
- System.out.println("The area of the circle is "+meters+"m^2, "+cm+"cm^2, "+mm+"mm^2.");
- break;
- case 'r':
- System.out.println("Please Enter the length of the rectangle in cm");
- length = sc.nextDouble();
- System.out.println("Please Enter the width of the rectangle in cm");
- width = sc.nextDouble();
- area = length*width;
- meters = (int)area/10000;
- cm = (int)area%10000;
- mm = (int)(area*10000%10000);
- mm = mm/100;
- System.out.println("The area of the rectangle is "+meters+"m^2, "+cm+"cm^2, "+mm+"mm^2.");
- break;
- case 't':
- System.out.println("Please enter the base of the triangle in mm");
- base = sc.nextDouble();
- System.out.println("Please enter the height of the triangle in mm");
- height = sc.nextDouble();
- area = 0.5*base*height;
- meters = (int)area/1000000;
- cm = (int)area/100%10000;
- mm = (int)((area*10)%1000);
- mm = mm/10;
- System.out.println("The area of the trianle is "+meters+"m^2, "+cm+"cm^2, "+mm+"mm^2.");
- break;
- case 'e':
- System.out.println("ADIOS");
- break;
- default:
- System.out.println("Please type in a correct option");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement