-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.java
More file actions
74 lines (57 loc) · 2.25 KB
/
Copy pathtest.java
File metadata and controls
74 lines (57 loc) · 2.25 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
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Select a shape to calculate area and perimeter:");
System.out.println("1. Circle");
System.out.println("2. Rectangle");
System.out.println("3. Square");
int choice = scanner.nextInt();
switch (choice) {
case 1:
circleCalculations();
break;
case 2:
rectangleCalculations();
break;
case 3:
squareCalculations();
break;
default:
System.out.println("Invalid choice. Please select a valid option.");
}
scanner.close();
}
private static void circleCalculations() {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the radius of the circle:");
double radius = scanner.nextDouble();
double area = Math.PI * Math.pow(radius, 2);
double perimeter = 2 * Math.PI * radius;
System.out.println("Area of the circle: " + area);
System.out.println("Perimeter of the circle: " + perimeter);
scanner.close();
}
private static void rectangleCalculations() {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the length of the rectangle:");
double length = scanner.nextDouble();
System.out.println("Enter the width of the rectangle:");
double width = scanner.nextDouble();
double area = length * width;
double perimeter = 2 * (length + width);
System.out.println("Area of the rectangle: " + area);
System.out.println("Perimeter of the rectangle: " + perimeter);
scanner.close();
}
private static void squareCalculations() {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the side length of the square:");
double side = scanner.nextDouble();
double area = Math.pow(side, 2);
double perimeter = 4 * side;
System.out.println("Area of the square: " + area);
System.out.println("Perimeter of the square: " + perimeter);
scanner.close();
}
}