Browse Source

geändert am 21.11.2023 um 16:33

master
leonmcfly 1 year ago
parent
commit
3cbe2b7cb2

BIN
out/production/Prog3/Praktikum03/TriangleChecker$1.class View File


BIN
out/production/Prog3/Praktikum03/TriangleChecker$TriangleType.class View File


BIN
out/production/Prog3/Praktikum03/TriangleChecker.class View File


BIN
out/production/Prog3/Praktikum03/Zahlenfilter.class View File


BIN
out/test/Prog3/Praktikum03/TriangleCheckerTest.class View File


BIN
out/test/Prog3/Praktikum03/ZahlenfilterTest.class View File


+ 59
- 0
src/Praktikum03/TriangleChecker.java View File

@@ -0,0 +1,59 @@
package Praktikum03;

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");
case NORMAL -> System.out.println("Dreieck");
case ISOSCELES -> System.out.println("Gleichschenkliges Dreieck");
case EQUILATERAL -> System.out.println("Gleichseitiges Dreieck");
}
}

// Analyse der Dreiecksart
public static TriangleType checkTriangle(float a, float b, float c) {


if(a == b && b == c)
return TriangleType.EQUILATERAL;
if(a == b || b == c || a == c)
return TriangleType.ISOSCELES;
if(a + b < c || a + c < b || b + c < a)
return TriangleType.NONE;
if(a < 0 || b < 0 || c < 0)
return TriangleType.NONE;

return TriangleType.NORMAL;
}


}

+ 36
- 9
test/Praktikum03/TriangleCheckerTest.java View File

@@ -6,15 +6,6 @@ import static org.junit.jupiter.api.Assertions.*;

class TriangleCheckerTest {

@Test
void checkTriangle() {
int a = 3;





}

@Test
void checkNormalTriangle() {
@@ -40,4 +31,40 @@ class TriangleCheckerTest {
assertEquals(TriangleChecker.TriangleType.EQUILATERAL, type);

}

@Test
void checkIsoscelesTriangle() {

float a = 3.0f;
float b = 4.0f;


TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a,b,a);

assertEquals(TriangleChecker.TriangleType.ISOSCELES, type);

}

@Test
void checkNumbersNegative(){
float a = 5.0f;
float b = -20.0f;
float c = 4.0f;

TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a,b,c);

assertEquals(TriangleChecker.TriangleType.NONE, type);
}

@Test
void checkIfSideToLong(){
float a = 3.0f;
float b = 20.0f;
float c = 5.0f;

TriangleChecker.TriangleType type = TriangleChecker.checkTriangle(a,b,c);

assertEquals(TriangleChecker.TriangleType.NONE, type);
}

}

Loading…
Cancel
Save