Implemented Figures classes with interface Area;

This commit is contained in:
Arkadiusz Hypki 2023-03-28 16:24:07 +02:00
parent 8e628a9c72
commit f1f961dd14
2 changed files with 9 additions and 7 deletions

View File

@ -1,13 +1,11 @@
package net.hypki.testjava.figures;
public abstract class Figure {
public abstract class Figure implements Area {
private int id = -1;
private String name;
public abstract double computeArea();
public Figure() {
setName("Figure");
}

View File

@ -31,10 +31,14 @@ public class Main {
System.out.println(t.getColor());
Area a = new Triangle(4, 10);
a = new Rectangle(4, 10);
a = new Circle(10.0);
System.out.println(a);
if (a instanceof Triangle)
System.out.println(((Triangle) a).getColor());
else if (a instanceof Circle)
System.out.println(((Circle) a).getRadius());
}
}