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");
|
||||
}
|
||||
|
@ -30,11 +30,15 @@ public class Main {
|
||||
Triangle t = new Triangle(1, 2);
|
||||
System.out.println(t.getColor());
|
||||
|
||||
Area a = new Triangle(4, 10);
|
||||
Area a = new Triangle(4, 10);
|
||||
a = new Rectangle(4, 10);
|
||||
a = new Circle(10.0);
|
||||
System.out.println(a);
|
||||
|
||||
|
||||
System.out.println(((Triangle) a).getColor());
|
||||
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