Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Lab3Exercise {
  4.  
  5. public static void main(String[] args) {
  6. System.out.print(
  7. "Please select from the following menu:\n"
  8. + "1. Rectangle Properties\n"
  9. + "2. Circle Properties\n"
  10. + "3. Exit\n"
  11. + "Selection: "
  12. );
  13. Scanner scanIn = new Scanner(System.in);
  14. int selection = scanIn.nextInt();
  15. switch (selection) {
  16. case 1:
  17. System.out.print("Input the width of the rectangle: ");
  18. int width = scanIn.nextInt();
  19. System.out.print("Input the height of the rectangle: ");
  20. int height = scanIn.nextInt();
  21. System.out.println("The area of the rectangle is " + rectangle(width, height));
  22. break;
  23. case 2:
  24. System.out.print("Input the radius of the circle: ");
  25. int radius = scanIn.nextInt();
  26. System.out.println("The area of the circle is " + circle(radius));
  27. break;
  28. }
  29. }
  30.  
  31. private static double circle(int i) {
  32. return (double) i * i * 22 / 7;
  33. }
  34.  
  35. private static int rectangle(int w, int h) {
  36. return w * h;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement