Another small improvements;

This commit is contained in:
Arkadiusz Hypki 2023-03-28 15:40:22 +02:00
parent 27cf59e60c
commit 578eace71c
3 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,5 @@
package net.hypki.testjava.figures;
public interface Area {
public double computeArea();
}

View File

@ -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;
}
}

View File

@ -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());
}
}