Browse Source

final Version Checker

master
felixdennerlein 2 years ago
parent
commit
c467d46e31

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

<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

<?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

<?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

<?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

<?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

<?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

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
} }



public static void main(String[] args) { public static void main(String[] args) {
Scanner s = new Scanner(System.in); Scanner s = new Scanner(System.in);
System.out.println("Geben Sie die Seitenlängen ein."); System.out.println("Geben Sie die Seitenlängen ein.");
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) {
//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; return TriangleType.NONE;
} }



} }

+ 29
- 2
test/TriangleCheckerTest.java View File

float c = 4; float c = 4;


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


// Assert // 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