Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Lab3Exercise {
- public static void main(String[] args) {
- System.out.print(
- "Please select from the following menu:\n"
- + "1. Rectangle Properties\n"
- + "2. Circle Properties\n"
- + "3. Exit\n"
- + "Selection: "
- );
- Scanner scanIn = new Scanner(System.in);
- int selection = scanIn.nextInt();
- switch (selection) {
- case 1:
- System.out.print("Input the width of the rectangle: ");
- int width = scanIn.nextInt();
- System.out.print("Input the height of the rectangle: ");
- int height = scanIn.nextInt();
- System.out.println("The area of the rectangle is " + rectangle(width, height));
- break;
- case 2:
- System.out.print("Input the radius of the circle: ");
- int radius = scanIn.nextInt();
- System.out.println("The area of the circle is " + circle(radius));
- break;
- }
- }
- private static double circle(int i) {
- return (double) i * i * 22 / 7;
- }
- private static int rectangle(int w, int h) {
- return w * h;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement