@@ -3,9 +3,12 @@ | |||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | |||
<exclude-output /> | |||
<content url="file://$MODULE_DIR$"> | |||
<sourceFolder url="file://$MODULE_DIR$/Test" isTestSource="true" /> | |||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | |||
</content> | |||
<orderEntry type="inheritedJdk" /> | |||
<orderEntry type="sourceFolder" forTests="false" /> | |||
<orderEntry type="library" name="junit.jupiter" level="project" /> | |||
<orderEntry type="library" name="mockito.core" level="project" /> | |||
</component> | |||
</module> |
@@ -0,0 +1,36 @@ | |||
import org.junit.jupiter.api.Test; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
class TriangleCheckerTest { | |||
@Test | |||
void checkNone() { | |||
assertEquals(TriangleChecker.TriangleType.NONE, TriangleChecker.checkTriangle(0, 0, 0)); | |||
} | |||
@Test | |||
void checkNormal() { | |||
assertEquals(TriangleChecker.TriangleType.NORMAL, TriangleChecker.checkTriangle(1, 2, 3)); | |||
} | |||
@Test | |||
void checkISOSCELES() { | |||
assertEquals(TriangleChecker.TriangleType.ISOSCELES, TriangleChecker.checkTriangle(1, 1, 2)); | |||
} | |||
@Test | |||
void checkEQUILATERAL() { | |||
assertEquals(TriangleChecker.TriangleType.EQUILATERAL, TriangleChecker.checkTriangle(1, 1, 1)); | |||
} | |||
} |
@@ -0,0 +1,27 @@ | |||
package praktikum01; | |||
import org.junit.jupiter.api.Test; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
class ZahlenfilterTest { | |||
@Test | |||
void filter() { | |||
} | |||
@Test | |||
void checkDivisibleBy5() { | |||
assertTrue(Zahlenfilter.checkDivisibleBy5(5)); | |||
assertFalse(Zahlenfilter.checkDivisibleBy5(6)); | |||
} | |||
@Test | |||
void checkEndsWith9() { | |||
} | |||
@Test | |||
void checkSumDivisibleBy3() { | |||
} | |||
} |
@@ -0,0 +1,67 @@ | |||
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){ | |||
return TriangleType.NONE; | |||
} | |||
if ( a == b && b == c){ | |||
return TriangleType.EQUILATERAL; | |||
} | |||
if (a == b && c > 0 || c == b && a > 0 || c == a && b > 0){ | |||
return TriangleType.ISOSCELES; | |||
} | |||
return TriangleType.NORMAL; | |||
} | |||
} |
@@ -0,0 +1,9 @@ | |||
package praktikum01; | |||
public class ErrorWriter implements HelloWorldTest{ | |||
@Override | |||
public void writeHelloWorld() { | |||
System.err.println("HELLO WORLD"); | |||
} | |||
} |
@@ -0,0 +1,9 @@ | |||
package praktikum01; | |||
public class Executor implements HelloWorldTest{ | |||
@Override | |||
public void printHelloWorld() { | |||
} | |||
} |
@@ -0,0 +1,8 @@ | |||
package praktikum01; | |||
public interface HelloWorldTest { | |||
void writeHelloWorld(); | |||
} | |||
@@ -0,0 +1,9 @@ | |||
package praktikum01; | |||
public class OutWriter implements HelloWorldTest{ | |||
@Override | |||
public void writeHelloWorld() { | |||
System.out.println("HELLO WORLD"); | |||
} | |||
} |
@@ -0,0 +1,4 @@ | |||
package praktikum01; | |||
public interface PasswordChecker { | |||
} |
@@ -1,45 +1,38 @@ | |||
package praktikum01; | |||
public class Zahlenfilter { | |||
public static void main(String[] args) { | |||
for (int i = 1; i < 200; i++) { | |||
int vorgaenger = i-1; | |||
int ergebnis = i+vorgaenger; | |||
if(i % 5 == 0){ | |||
System.out.println(i + " ist durch 5 teilbar"); | |||
if(ergebnis % 3 == 0){ | |||
System.out.println(i + " und "+ vorgaenger + " addiert ergeben " + ergebnis + " und " + ergebnis + " ist durch 3 teilbar"); | |||
} | |||
} | |||
if(i % 10 == 9){ | |||
System.out.println(i + " endet auf 9"); | |||
if(ergebnis % 3 == 0){ | |||
System.out.println(i + " und "+ vorgaenger + " addiert ergeben " + ergebnis + " und " + ergebnis + " ist durch 3 teilbar"); | |||
public class Zahlenfilter { | |||
int boundary = 5000; | |||
} | |||
public static void main(String[] args) { | |||
Zahlenfilter zahlenfilter = new Zahlenfilter(); | |||
zahlenfilter.printNumbers(); | |||
} | |||
private void printNumbers(){ | |||
for (int i=1; i<=boundary; i++){ | |||
if (filter(i)){ | |||
System.out.println(i); | |||
} | |||
} | |||
} | |||
public static boolean filter(int i){ | |||
return !(checkDivisibleBy5(i) || checkEndsWith9(i) || checkSumDivisibleBy3(i, i-1)); | |||
} | |||
public static boolean checkDivisibleBy5(int i){ | |||
return i % 2 == 0; | |||
} | |||
public static boolean checkEndsWith9(int i){ | |||
return i % 10 == 9; | |||
} | |||
} | |||
public static boolean checkSumDivisibleBy3(int i, int j){ | |||
return i + j % 3 == 0; | |||
} | |||
} | |||