abstract class Figura{
protected double podst;
public Figura(double p) {
podst=p; }
public double pole() {
return wysokosc()*podstawa(); }
public final double podstawa(){
return podst; }
public abstract double wysokosc();
}
class Kwadrat extends Figura {
public Kwadrat(double a) {super(a);}
public double wysokosc() {
return podst; }
}
class Prostokat extends Figura {
protected double b;
public Prostokat(double a, double b){
super(a); this.b=b;}
public double wysokosc()
{ return b; }
}
class Romb extends Figura {
protected double alpha;
public Romb(double a, double d) {
super(a); alpha=d; }
public double wysokosc() {
return Math.sin(alpha)*podstawa(); }
}
public class Figury {
public static void main(String args[]){
Figura[] figury = new Figura[3];
figury[0] = new Kwadrat(1);
figury[1] = new Prostokat(1,1);
figury[2] = new Romb(1, Math.PI/2);
double d=0;
for (Figura f: figury)
d += f.pole();
System.out.println("Pole figur: "+d);
}
}