Browse Source

Test: ISOSCELES

master
Orlando 1 year ago
parent
commit
c29dc4c6d9
2 changed files with 72 additions and 0 deletions
  1. 68
    0
      src/Prak1/TriangleChecker.java
  2. 4
    0
      test/Prak1/TriangleCheckerTest.java

+ 68
- 0
src/Prak1/TriangleChecker.java View File

@@ -0,0 +1,68 @@
package Prak1;
import java.util.Scanner;


public class TriangleChecker {

public enum TriangleType {
NONE,
NORMAL,
ISOSCELES, // Gleichschenklig
EQUILATERAL // Gleichseitig
}


public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Geben Sie die Seitenlängen ein.");
float a = enterFloat(s, "a: ");
float b = enterFloat(s, "b: ");
float c = enterFloat(s, "c: ");
s.close();
printAnalysis(a, b, c);
}

// Eingabe einer Seitenlänge
private static float enterFloat(Scanner s, String prompt) {
System.out.print(prompt);
return s.nextFloat();
}

// Ausgabe der ermittelten Dreiecksart
private static void printAnalysis(float a, float b, float c) {
TriangleType type = checkTriangle(a, b, c);
switch (type) {
case NONE:
System.out.println("Kein Dreieck");
break;
case NORMAL:
System.out.println("Dreieck");
break;
case ISOSCELES:
System.out.println("Gleichschenkliges Dreieck");
break;
case EQUILATERAL:
System.out.println("Gleichseitiges Dreieck");
break;
}
}

// Analyse der Dreiecksart
public static TriangleType checkTriangle(float a, float b, float c) {
if ((a < 0 || b < 0 || c < 0) || ((a + b) < c || (b + c) < a) || (a + c) < b) {
return TriangleType.NONE;
} else {
if (a == b & b == c) {
return TriangleType.EQUILATERAL;
} else {
if (a == b || b == c || a == c) {
return TriangleType.ISOSCELES;
} else {
return TriangleType.NORMAL;

}
}
}
}
}


+ 4
- 0
test/Prak1/TriangleCheckerTest.java View File

@@ -18,4 +18,8 @@ class TriangleCheckerTest {
void checkTriangle_none() {
assertEquals(TriangleChecker.TriangleType.NONE, TriangleChecker.checkTriangle(-10, 0, 10));
}
@Test
void checkTriangle_gleichschenklig() {
assertEquals(TriangleChecker.TriangleType.ISOSCELES, TriangleChecker.checkTriangle(10, 10, 5));
}
}

Loading…
Cancel
Save