Ramirez_RD

num3

Aug 7th, 2025
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.12 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SamsonGradedExer2Num3 {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         char choice;
  7.  
  8.         System.out.println("Choose a shape to compute the area:");
  9.         System.out.println("C - Circle");
  10.         System.out.println("S - Square");
  11.         System.out.println("R - Rectangle");
  12.         System.out.println("T - Triangle");
  13.         System.out.print("Enter your choice: ");
  14.         choice = sc.next().toUpperCase().charAt(0);
  15.  
  16.         switch (choice) {
  17.             case 'C':
  18.                 System.out.print("Enter the radius of the circle: ");
  19.                 double radius = sc.nextDouble();
  20.                 double circleArea = Math.PI * radius * radius;
  21.                 System.out.println("Area of the Circle = " + circleArea);
  22.                 break;
  23.  
  24.             case 'S':
  25.                 System.out.print("Enter the side of the square: ");
  26.                 double side = sc.nextDouble();
  27.                 double squareArea = side * side;
  28.                 System.out.println("Area of the Square = " + squareArea);
  29.                 break;
  30.  
  31.             case 'R':
  32.                 System.out.print("Enter the length of the rectangle: ");
  33.                 double length = sc.nextDouble();
  34.                 System.out.print("Enter the width of the rectangle: ");
  35.                 double width = sc.nextDouble();
  36.                 double rectangleArea = length * width;
  37.                 System.out.println("Area of the Rectangle = " + rectangleArea);
  38.                 break;
  39.  
  40.             case 'T':
  41.                 System.out.print("Enter the base of the triangle: ");
  42.                 double base = sc.nextDouble();
  43.                 System.out.print("Enter the height of the triangle: ");
  44.                 double height = sc.nextDouble();
  45.                 double triangleArea = 0.5 * base * height;
  46.                 System.out.println("Area of the Triangle = " + triangleArea);
  47.                 break;
  48.  
  49.             default:
  50.                 System.out.println("Invalid choice. Please choose C, S, R, or T.");
  51.         }
  52.  
  53.         sc.close();
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment