Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class SamsonGradedExer2Num3 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- char choice;
- System.out.println("Choose a shape to compute the area:");
- System.out.println("C - Circle");
- System.out.println("S - Square");
- System.out.println("R - Rectangle");
- System.out.println("T - Triangle");
- System.out.print("Enter your choice: ");
- choice = sc.next().toUpperCase().charAt(0);
- switch (choice) {
- case 'C':
- System.out.print("Enter the radius of the circle: ");
- double radius = sc.nextDouble();
- double circleArea = Math.PI * radius * radius;
- System.out.println("Area of the Circle = " + circleArea);
- break;
- case 'S':
- System.out.print("Enter the side of the square: ");
- double side = sc.nextDouble();
- double squareArea = side * side;
- System.out.println("Area of the Square = " + squareArea);
- break;
- case 'R':
- System.out.print("Enter the length of the rectangle: ");
- double length = sc.nextDouble();
- System.out.print("Enter the width of the rectangle: ");
- double width = sc.nextDouble();
- double rectangleArea = length * width;
- System.out.println("Area of the Rectangle = " + rectangleArea);
- break;
- case 'T':
- System.out.print("Enter the base of the triangle: ");
- double base = sc.nextDouble();
- System.out.print("Enter the height of the triangle: ");
- double height = sc.nextDouble();
- double triangleArea = 0.5 * base * height;
- System.out.println("Area of the Triangle = " + triangleArea);
- break;
- default:
- System.out.println("Invalid choice. Please choose C, S, R, or T.");
- }
- sc.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment