forked from VimalKrishnaRao/OOP-in-Java-Lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3PerimeterCalculator.java
53 lines (47 loc) · 1.21 KB
/
3PerimeterCalculator.java
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
import java.util.Scanner;
class Circle
{
private double radius;
public Circle(double radius)
{
System.out.println("The perimeter of the circle is: " + (2 * Math.PI * radius));
}
}
class Rectangle
{
private double width;
private double height;
public Rectangle(double width, double height)
{
System.out.println("The perimeter of the rectangle is: " + (2 * (width + height)));
}
}
public class Main
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Please select a shape: ");
System.out.println("1. Circle");
System.out.println("2. Rectangle");
int shape = sc.nextInt();
if (shape == 1)
{
System.out.println("Enter the radius of the circle: ");
double radius = sc.nextDouble();
Circle circle = new Circle(radius);
}
else if (shape == 2)
{
System.out.println("Enter the width of the rectangle: ");
double width = sc.nextDouble();
System.out.println("Enter the height of the rectangle: ");
double height = sc.nextDouble();
Rectangle rectangle = new Rectangle(width, height);
}
else
{
System.out.println("Invalid shape selection.");
}
}
}