-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShape.94.java
68 lines (56 loc) · 1.18 KB
/
Shape.94.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
abstract class Shape
{
public abstract double getArea();
}
class Circle extends Shape
{
private double radius;
public Circle(double radius)
{
this.radius = radius;
}
public double getArea()
{
return Math.PI * radius * radius;
}
}
class Rectangle extends Shape
{
private double width;
private double height;
public Rectangle(double width, double height)
{
this.width = width;
this.height = height;
}
public double getArea()
{
return width * height;
}
}
class Triangle extends Shape
{
private double base;
private double height;
public Triangle(double base, double height)
{
this.base = base;
this.height = height;
}
public double getArea()
{
return 0.5 * base * height;
}
}
public class Shape94
{
public static void main(String[] args)
{
Shape circle = new Circle(5);
Shape rectangle = new Rectangle(4, 6);
Shape triangle = new Triangle(3, 4);
System.out.println("Circle Area: " + circle.getArea());
System.out.println("Rectangle Area: " + rectangle.getArea());
System.out.println("Triangle Area: " + triangle.getArea());
}
}