tracks/java/exercises/triangle/.meta/src/reference/java/Triangle.java in trackler-2.2.1.41 vs tracks/java/exercises/triangle/.meta/src/reference/java/Triangle.java in trackler-2.2.1.42
- old
+ new
@@ -4,32 +4,33 @@
class Triangle {
private double side1;
private double side2;
private double side3;
+ private int uniqueSides;
Triangle(double side1, double side2, double side3) throws TriangleException {
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
if (allSidesAreZero() || hasImpossibleSides() || violatesTriangleInequality()) {
throw new TriangleException();
}
+
+ this.uniqueSides = getNumberOfUniqueSides();
}
- TriangleKind getKind() {
- int uniqueSides = getNumberOfUniqueSides();
+ boolean isEquilateral() {
+ return uniqueSides == 1;
+ }
- if (uniqueSides == 1) {
- return TriangleKind.EQUILATERAL;
- }
+ boolean isIsosceles() {
+ return uniqueSides == 2;
+ }
- if (uniqueSides == 2) {
- return TriangleKind.ISOSCELES;
- }
-
- return TriangleKind.SCALENE;
+ boolean isScalene() {
+ return uniqueSides == 3;
}
private boolean allSidesAreZero() {
return side1 == 0 && side2 == 0 && side3 == 0;
}