-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
78 lines (74 loc) · 3.05 KB
/
Main.java
File metadata and controls
78 lines (74 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
Name:Lakshya Joshi
PRN:23070126065
Batch:AIML A3
*/
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int choice;
do {
System.out.println("\n=== Shape Calculator ===");
System.out.println("1. Circle");
System.out.println("2. Rectangle");
System.out.println("3. Square");
System.out.println("4. Sphere");
System.out.println("5. Cylinder");
System.out.println("6. Equilateral Pyramid");
System.out.println("7. Exit");
System.out.print("Enter your choice: ");
choice = scanner.nextInt();
switch (choice) {
case 1:
System.out.print("Enter radius: ");
double radius = scanner.nextDouble();
Circle circle = new Circle(radius);
circle.displayResults();
break;
case 2:
System.out.print("Enter length: ");
double length = scanner.nextDouble();
System.out.print("Enter width: ");
double width = scanner.nextDouble();
Rectangle rectangle = new Rectangle(length, width);
rectangle.displayResults();
break;
case 3:
System.out.print("Enter side: ");
double side = scanner.nextDouble();
Square square = new Square(side);
square.displayResults();
break;
case 4:
System.out.print("Enter radius: ");
double sphereRadius = scanner.nextDouble();
Sphere sphere = new Sphere(sphereRadius);
sphere.displayResults();
break;
case 5:
System.out.print("Enter radius: ");
double cylRadius = scanner.nextDouble();
System.out.print("Enter height: ");
double height = scanner.nextDouble();
Cylinder cylinder = new Cylinder(cylRadius, height);
cylinder.displayResults();
break;
case 6:
System.out.print("Enter base side: ");
double baseSide = scanner.nextDouble();
System.out.print("Enter height: ");
double pyramidHeight = scanner.nextDouble();
EquilateralPyramid pyramid = new EquilateralPyramid(baseSide, pyramidHeight);
pyramid.displayResults();
break;
case 7:
System.out.println("Exiting program. Thank you!");
break;
default:
System.out.println("Invalid choice. Please try again.");
}
} while (choice != 7);
scanner.close();
}
}