[text] Main.java

Viewer

copydownloadembedprintName: Main.java
  1. public class Main {
  2.     public static void main(String[] args) {
  3.         Scanner scanner = new Scanner(System.in);
  4.         System.out.println("Enter the shape\n1.Rectangle\n2.Triangle");
  5.         int option = scanner.nextInt();
  6.         switch (option) {
  7.             case 1:
  8.                 System.out.println("Enter the length and breadth:");
  9.                 Shape.value1 = scanner.nextDouble();
  10.                 Shape.value2 = scanner.nextDouble();
  11.                 Shape.Rectangle rectangle = new Shape.Rectangle();
  12.                 double rectangleArea = rectangle.computeRectangleArea();
  13.                 System.out.printf("Area of rectangle is %.2f\n", rectangleArea);
  14.                 break;
  15.             case 2:
  16.                 System.out.println("Enter the base and height:");
  17.                 Shape.value1 = scanner.nextDouble();
  18.                 Shape.value2 = scanner.nextDouble();
  19.                 Shape.Triangle triangle = new Shape.Triangle();
  20.                 double triangleArea = triangle.computeTriangleArea();
  21.                 System.out.printf("Area of triangle is %.2f\n", triangleArea);
  22.                 break;
  23.             default:
  24.                 System.out.println("Invalid choice");
  25.         }
  26.     }
  27. }
  28.  

Editor

You can edit this paste and save as new:


File Description
  • Main.java
  • Paste Code
  • 20 May-2024
  • 1.21 Kb
You can Share it: