Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MathMenu {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- //Geometry geometry = new Geometry();
- int choice = 0;
- // Loops indefinitely until the user enters an int between 1 and 4 (inclusive).
- while(choice < 1 || choice > 4) {
- System.out.println("1. Calculate the Area of a Circle");
- System.out.println("2. Calculate the Area of a Rectangle");
- System.out.println("3. Calculate the Area of a Triangle");
- System.out.println("4. Quit");
- // This line will prevent instantaneous looping, aka the terrible Infinite Loop!
- choice = input.nextInt();
- }
- switch (choice)
- {
- case 1:
- System.out.println("Radius of circle");
- double r = input.nextDouble();
- //System.out.println("Area: " + geometry.areaOfCircle(r));
- break;
- case 2:
- double l, w;
- System.out.println("Length of rectangle");
- l = input.nextDouble();
- System.out.println("Width of rectangle");
- w = input.nextDouble();
- //System.out.println("Area: " + geometry.areaOfRectangle(l, w));
- break;
- case 3:
- double b, h;
- System.out.println("Base of triangle");
- b = input.nextDouble();
- System.out.println("Height of triangle");
- h = input.nextDouble();
- //System.out.println("Area: " + geometry.areaOfTriangle(b, h));
- break;
- case 4:
- System.out.println("Quitting");
- input.close();
- System.exit(0);
- break;
- default:
- System.out.println("This should be unreachable, if this prints... well oh dear!");
- input.close();
- System.exit(-1);
- break;
- }
- input.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement