Browse Source

Commit

master
David Papac 2 years ago
parent
commit
4006f9b4cb
2 changed files with 20 additions and 7 deletions
  1. 18
    7
      src/TriangleChecker.java
  2. 2
    0
      test/TriangleCheckerTest.java

+ 18
- 7
src/TriangleChecker.java View File

import java.util.Scanner; import java.util.Scanner;


public class TriangleChecker { public class TriangleChecker {
public enum TriangleType { public enum TriangleType {
NONE,
NONE,
NORMAL, NORMAL,
ISOSCELES, // Gleichschenklig ISOSCELES, // Gleichschenklig
EQUILATERAL // Gleichseitig EQUILATERAL // Gleichseitig
switch (type) { switch (type) {
case NONE: case NONE:
System.out.println("Kein Dreieck"); System.out.println("Kein Dreieck");
break;
break;
case NORMAL: case NORMAL:
System.out.println("Dreieck"); System.out.println("Dreieck");
break;
break;
case ISOSCELES: case ISOSCELES:
System.out.println("Gleichschenkliges Dreieck"); System.out.println("Gleichschenkliges Dreieck");
break;
break;
case EQUILATERAL: case EQUILATERAL:
System.out.println("Gleichseitiges Dreieck"); System.out.println("Gleichseitiges Dreieck");
break;
break;
} }
} }


// Analyse der Dreiecksart // Analyse der Dreiecksart
public static TriangleType checkTriangle(float a, float b, float c) { public static TriangleType checkTriangle(float a, float b, float c) {
if (triangleTheorem(a,b,c) ){
if(a==b && a==c){return TriangleType.EQUILATERAL;}
if(a==b||b==c||a==c){return TriangleType.ISOSCELES;}

return TriangleType.NORMAL;
}
return TriangleType.NONE; return TriangleType.NONE;
} }



public static boolean triangleTheorem(float a, float b, float c) {
if (a <= 0 || b <= 0 || c <= 0) {
return false;
}
return (a + b > c && b + c > a && a + c > b);
}
} }

+ 2
- 0
test/TriangleCheckerTest.java View File



// Assert // Assert
assertEquals(TriangleChecker.TriangleType.NORMAL, type); assertEquals(TriangleChecker.TriangleType.NORMAL, type);
assertEquals(TriangleChecker.TriangleType.EQUILATERAL, type);
assertEquals(TriangleChecker.TriangleType.ISOSCELES, type);


} }



Loading…
Cancel
Save