@@ -0,0 +1,56 @@ | |||
package praktikum02; | |||
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) { | |||
return TriangleType.NORMAL; | |||
} | |||
} |
@@ -0,0 +1,73 @@ | |||
package praktikum02; | |||
public class Zahlenfilter { | |||
int length = 200; | |||
public static void main(String[] args) { | |||
Zahlenfilter zahlenfilter = new Zahlenfilter(); | |||
if(args.length >0){ | |||
try{ | |||
zahlenfilter.length = Integer.parseInt(args[0]); | |||
} | |||
catch (NumberFormatException e){ | |||
System.out.println("Das geht nicht. Default: 200"); | |||
} | |||
} | |||
zahlenfilter.checknumber(); | |||
} | |||
public void checknumber(){ | |||
for (int i = 1; i <= length; i++) { | |||
if (filter(i)) { | |||
System.out.println(i + " erfüllt kein Kriterium"); | |||
} | |||
} | |||
} | |||
public void checkDurch5(int zahl) { | |||
if (zahl % 5 == 0) { | |||
System.out.println(zahl + " ist durch 5 teilbar!"); | |||
} | |||
} | |||
public void checkEndet9(int zahl) { | |||
if (zahl % 10 == 9) { | |||
System.out.println(zahl + " endet auf 9!"); | |||
} | |||
} | |||
public void checkSummeDurch3(int zahl, int vorgaenger) { | |||
int summe = zahl + vorgaenger; | |||
if (summe % 3 == 0) { | |||
System.out.println(zahl + " und " + vorgaenger + " addiert ergeben " | |||
+ summe + " und " + summe + " ist durch 3 teilbar!"); | |||
} | |||
} | |||
public void printNumbers(){ | |||
for (int i=1; i<length; i++) | |||
if (filter(i)) | |||
System.out.println(i); | |||
} | |||
public static boolean filter(int i){ | |||
return !(checkDivisibleBy5(i)|| checkEndsWith9(i) || checkSumDivisibleBy3(i)); | |||
} | |||
public static boolean checkDivisibleBy5(int number) { | |||
return number % 5 == 0; | |||
} | |||
public static boolean checkEndsWith9(int number) { | |||
return number % 10 == 9; | |||
} | |||
public static boolean checkSumDivisibleBy3(int number) { | |||
int pred = number - 1; | |||
int sum = number + pred; | |||
return sum % 3 == 0; | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
package praktikum02; | |||
import org.junit.jupiter.api.Test; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
class TriangleCheckerTest { | |||
@Test | |||
void checkTriangle() { | |||
assertEquals(TriangleChecker.TriangleType.NORMAL,TriangleChecker.checkTriangle(5,6,7)); | |||
} | |||
} |
@@ -0,0 +1,25 @@ | |||
package praktikum02; | |||
import static org.junit.jupiter.api.Assertions.*; | |||
class ZahlenfilterTest { | |||
@org.junit.jupiter.api.Test | |||
void filter() { | |||
assertTrue(Zahlenfilter.filter(30)); | |||
assertFalse(Zahlenfilter.filter(31)); | |||
} | |||
@org.junit.jupiter.api.Test | |||
void checkDivisibleBy5() { | |||
assertTrue(Zahlenfilter.checkDivisibleBy5(32)); | |||
} | |||
@org.junit.jupiter.api.Test | |||
void checkEndsWith9() { | |||
} | |||
@org.junit.jupiter.api.Test | |||
void checkSumDivisibleBy3() { | |||
} | |||
} |