Implemented Figures classes with interface Area;
This commit is contained in:
parent
8e628a9c72
commit
f1f961dd14
@ -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");
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user