Browse Source

final Version Checker

master
felixdennerlein 2 years ago
parent
commit
c467d46e31

+ 10
- 0
.idea/libraries/jars.xml View File

@@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="jars">
<CLASSES>
<root url="jar://$PROJECT_DIR$/jars/junit-4.12.jar!/" />
<root url="jar://$PROJECT_DIR$/jars/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

+ 6
- 0
.idea/misc.xml View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

+ 8
- 0
.idea/modules.xml View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/TriangleCheckerAssignment.iml" filepath="$PROJECT_DIR$/TriangleCheckerAssignment.iml" />
</modules>
</component>
</project>

+ 10
- 0
.idea/runConfigurations.xml View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

+ 6
- 0
.idea/vcs.xml View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

+ 13
- 0
TriangleCheckerAssignment.iml View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="jars" level="project" />
</component>
</module>

+ 20
- 8
src/TriangleChecker.java View File

@@ -1,15 +1,14 @@
import java.util.Scanner;

public class TriangleChecker {
public enum TriangleType {
NONE,
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.");
@@ -32,23 +31,36 @@ public class TriangleChecker {
switch (type) {
case NONE:
System.out.println("Kein Dreieck");
break;
break;
case NORMAL:
System.out.println("Dreieck");
break;
break;
case ISOSCELES:
System.out.println("Gleichschenkliges Dreieck");
break;
break;
case EQUILATERAL:
System.out.println("Gleichseitiges Dreieck");
break;
break;
}
}

// Analyse der Dreiecksart
public static TriangleType checkTriangle(float a, float b, float c) {
//check for shape
if (a + b > c && a + c > b && b + c > a) {
if (a == b && b == c) {
//gleichseitiges Dreieck
return TriangleType.EQUILATERAL;
}
if (a == b || a == c || b == c) {
//gleichschenkliges Dreieck
return TriangleType.ISOSCELES;
}
//normales Dreieck
return TriangleType.NORMAL;
}
//kein Dreieck
return TriangleType.NONE;
}


}

+ 29
- 2
test/TriangleCheckerTest.java View File

@@ -12,10 +12,37 @@ public class TriangleCheckerTest {
float c = 4;

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

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

//Arrange
a = 1; b = 10; c = 1;

//Act
TriangleChecker.TriangleType none = TriangleChecker.checkTriangle(a, b, c);

//Assert
assertEquals(TriangleChecker.TriangleType.NONE, none);

//Arrange
a = 3; b = 3; c = 2;

//Act
TriangleChecker.TriangleType iso = TriangleChecker.checkTriangle(a, b, c);

//Assert
assertEquals(TriangleChecker.TriangleType.ISOSCELES, iso);

//Arrange
a = 4; b = 4; c = 4;

//Act
TriangleChecker.TriangleType equi = TriangleChecker.checkTriangle(a, b, c);

//Assert
assertEquals(TriangleChecker.TriangleType.EQUILATERAL, equi);

}


Loading…
Cancel
Save