<exclude-output /> | <exclude-output /> | ||||
<content url="file://$MODULE_DIR$"> | <content url="file://$MODULE_DIR$"> | ||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> | |||||
</content> | </content> | ||||
<orderEntry type="inheritedJdk" /> | <orderEntry type="inheritedJdk" /> | ||||
<orderEntry type="sourceFolder" forTests="false" /> | <orderEntry type="sourceFolder" forTests="false" /> | ||||
<orderEntry type="library" name="junit.jupiter" level="project" /> | |||||
</component> | </component> | ||||
</module> | </module> |
package Praktikum03; | |||||
public class Zahlenfilter { | |||||
public static void main(String[] args) { | |||||
int upper_limit = 200; | |||||
if (args.length > 0) | |||||
upper_limit = Integer.parseInt(args[0]); | |||||
Zahlenfilter z = new Zahlenfilter(upper_limit); | |||||
z.printNumber(); | |||||
} | |||||
private int boundary; | |||||
private Zahlenfilter(int limit){ | |||||
boundary = limit; | |||||
} | |||||
private void printNumber(){ | |||||
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 % 5 == 0); | |||||
} | |||||
public static boolean checkEndsWith9(int i){ | |||||
return(i % 10 == 9); | |||||
} | |||||
public static boolean checkSumDivisibleBy3(int i, int j){ | |||||
return((i+j) % 3 == 0); | |||||
} | |||||
} |
package Praktikum03; | |||||
import org.junit.jupiter.api.Test; | |||||
import static org.junit.jupiter.api.Assertions.*; | |||||
class ZahlenfilterTest { | |||||
@Test | |||||
void filter() { | |||||
} | |||||
@Test | |||||
void checkDivisibleBy5() { | |||||
int i = 15; | |||||
boolean result = Zahlenfilter.checkDivisibleBy5(i); | |||||
assertTrue(result); | |||||
} | |||||
@Test | |||||
void checkNotDivisibleBy5() { | |||||
int i = 12; | |||||
boolean result = Zahlenfilter.checkDivisibleBy5(i); | |||||
assertFalse(result); | |||||
} | |||||
@Test | |||||
void checkEndsWith9() { | |||||
int i = 29; | |||||
boolean result = Zahlenfilter.checkEndsWith9(i); | |||||
assertTrue(result); | |||||
} | |||||
@Test | |||||
void checkEndsNotWith9() { | |||||
int i = 28; | |||||
boolean result = Zahlenfilter.checkEndsWith9(i); | |||||
assertFalse(result); | |||||
} | |||||
@Test | |||||
void checkSumDivisibleBy3() { | |||||
int i = 5; | |||||
boolean result = Zahlenfilter.checkSumDivisibleBy3(i, i-1); | |||||
assertTrue(result); | |||||
} | |||||
@Test | |||||
void checkSumNotDivisibleBy3() { | |||||
int i = 3; | |||||
boolean result = Zahlenfilter.checkSumDivisibleBy3(i, i-1); | |||||
assertFalse(result); | |||||
} | |||||
} |