-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem08.java
More file actions
42 lines (39 loc) · 797 Bytes
/
Problem08.java
File metadata and controls
42 lines (39 loc) · 797 Bytes
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
class Shape{
private double area;
public Shape(double a) {
area = a;
}
public double show() {
return this.area;
}
}
class Circle extends Shape{
public Circle(double r) {
super((r*r) * Math.PI);
}
}
class Square extends Shape{
public Square(double a) {
super(a*a);
}
}
class Rectangle extends Shape{
public Rectangle(double a, double b) {
super(a*b);
}
}
public class Problem08 {
public static double sumArea(Shape[] a) {
double sum = 0;
for(int i = 0; i < a.length; i++){
sum += a[i].show();
}
return sum;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Shape[] arr = {new Circle(5.0), new Square(4.0),
new Rectangle (3.0,4.0), new Square(5.0)};
System.out.println("Total area of the shapes is: " + sumArea(arr));
}
}