geändert am 21.11.2023 um 15:27
This commit is contained in:
parent
15d7358bfe
commit
ee07f5e279
@ -4,8 +4,10 @@
|
|||||||
<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>
|
43
src/Praktikum03/Zahlenfilter.java
Normal file
43
src/Praktikum03/Zahlenfilter.java
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
66
test/Praktikum03/ZahlenfilterTest.java
Normal file
66
test/Praktikum03/ZahlenfilterTest.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user