diff --git a/src/net/hypki/testjava/figures/Area.java b/src/net/hypki/testjava/figures/Area.java new file mode 100644 index 0000000..471caa2 --- /dev/null +++ b/src/net/hypki/testjava/figures/Area.java @@ -0,0 +1,5 @@ +package net.hypki.testjava.figures; + +public interface Area { + public double computeArea(); +} diff --git a/src/net/hypki/testjava/figures/Triangle.java b/src/net/hypki/testjava/figures/Triangle.java new file mode 100644 index 0000000..1ca0338 --- /dev/null +++ b/src/net/hypki/testjava/figures/Triangle.java @@ -0,0 +1,50 @@ +package net.hypki.testjava.figures; + +public class Triangle implements Area { + + private double a; + + private double h; + + private String color = "blue"; + + public Triangle(double a, double b) { + setA(a); + setH(b); + } + + @Override + public String toString() { + return "Triangle area = " + computeArea(); + } + + @Override + public double computeArea() { + return 0.5 * getA() * getH(); + } + + public double getA() { + return a; + } + + public void setA(double a) { + this.a = a; + } + + public double getH() { + return h; + } + + public void setH(double h) { + this.h = h; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + +} diff --git a/src/net/hypki/testjava/main/Main.java b/src/net/hypki/testjava/main/Main.java index 64c2d10..8e55ed1 100644 --- a/src/net/hypki/testjava/main/Main.java +++ b/src/net/hypki/testjava/main/Main.java @@ -1,9 +1,11 @@ package net.hypki.testjava.main; +import net.hypki.testjava.figures.Area; import net.hypki.testjava.figures.Circle; import net.hypki.testjava.figures.Figure; import net.hypki.testjava.figures.Rectangle; import net.hypki.testjava.figures.Square; +import net.hypki.testjava.figures.Triangle; public class Main { @@ -24,6 +26,15 @@ public class Main { Circle c = new Circle(3); System.out.println(c); + + Triangle t = new Triangle(1, 2); + System.out.println(t.getColor()); + + Area a = new Triangle(4, 10); + System.out.println(a); + + + System.out.println(((Triangle) a).getColor()); } }