added a class to test all features at once

This commit is contained in:
JonathanFleischmann 2024-07-04 18:34:32 +02:00
parent a3990ebbcd
commit 83942b2c05
3 changed files with 231 additions and 0 deletions

View File

@ -35,6 +35,7 @@
(so würde z.B. (true || false == false) false zurückgeben) (so würde z.B. (true || false == false) false zurückgeben)
- i++ und i-- sind nur in for-Schleifen oder Statements erlaubt, --i und ++i sind generell nicht erlaubt - i++ und i-- sind nur in for-Schleifen oder Statements erlaubt, --i und ++i sind generell nicht erlaubt
- ein File kann nur eine Klasse enthalten - ein File kann nur eine Klasse enthalten
- Datentypen sind auf int, boolean und char sowie Klassen beschränkt
## Aufbau der Tests ## Aufbau der Tests

View File

@ -0,0 +1,202 @@
public class AllFeaturesInOne {
// This is a comment
int repititionsOfSchema;
int maxLengthOfSchema;
char letter1;
char letter2;
char letter3;
boolean doStillExecuteAfterMaxLength;
Configuration configuration;
public AllFeaturesInOne() {
this.letter1 = 'a';
this.letter2 = 'b';
this.letter3 = 'c';
this.maxLengthOfSchema = 100;
this.doStillExecuteAfterMaxLength = false;
this.repititionsOfSchema = 5;
}
public AllFeaturesInOne(char letter3) {
this.letter1 = 'a';
this.letter2 = 'b';
this.letter3 = letter3;
this.maxLengthOfSchema = 100;
this.doStillExecuteAfterMaxLength = false;
this.repititionsOfSchema = 5;
}
public AllFeaturesInOne(int repititionsOfSchema, char letter3) {
this.repititionsOfSchema = repititionsOfSchema;
this.letter1 = 'a';
this.letter2 = 'b';
this.letter3 = letter3;
this.maxLengthOfSchema = 100;
this.doStillExecuteAfterMaxLength = false;
}
public AllFeaturesInOne(Configuration configuration) {
this.configuration = configuration;
this.repititionsOfSchema = configuration.getRepititionsOfSchema();
this.maxLengthOfSchema = configuration.maxLengthOfSchema;
this.letter1 = configuration.letter1;
this.letter2 = configuration.letter2;
this.letter3 = configuration.letter3;
this.doStillExecuteAfterMaxLength = configuration.doStillExecuteAfterMaxLength;
}
public void printFibonacciSchema(boolean withSpaceBetweenSteps) {
int number1 = 0;
int number2 = 1;
int numberOfLetter = 0;
for (int i = 0; i < this.repititionsOfSchema; i++) {
if(number2 == this.maxLengthOfSchema && !this.doStillExecuteAfterMaxLength) {
break;
}
int j;
for(j = number2; j > 0; j -= 1) {
if (numberOfLetter == 0) {
print(this.letter1);
} else if (numberOfLetter == 1) {
print(this.letter2);
} else {
print(this.letter3);
}
}
if (withSpaceBetweenSteps) {
print(' ');
}
numberOfLetter = (numberOfLetter + 1) % 3;
int sum = number1 + number2;
number1 = number2;
number2 = sum;
}
}
public void printFibonacciButWithMultiplication() {
int number1 = 1;
int number2 = 2;
int numberOfLetter = 0;
for (int i = 0; i < this.repititionsOfSchema; i += 1) {
if(number2 <= this.maxLengthOfSchema || this.doStillExecuteAfterMaxLength) {
int j;
for(j = 0; j < number2; j = j + 1) {
if (numberOfLetter == 0) {
print(this.letter1);
} else if (numberOfLetter == 1) {
print(this.letter2);
} else {
print(this.letter3);
}
}
print(' ');
numberOfLetter = (numberOfLetter + 1) % 3;
int number2OldValue = number2;
number2 *= number1;
number1 = number2OldValue;
} else {
return;
}
}
}
public void printEveryLetterXTimesAndSkipEveryYTimesComplex(int x, int y) {
int numberOfLetter = 0;
int rest = 0;
int numberOfRepititions;
int numberToDivide;
int numberOfRepetitionsWithoutSkip = 0;
do {
numberOfRepititions = (x - rest) - ((x - rest) / y);
if (rest > 0) {
numberOfRepititions += rest - 1;
}
rest = (y - ((x + (-rest)) % y)) % y;
while (numberOfRepititions > 0) {
numberOfRepetitionsWithoutSkip++;
if (numberOfRepetitionsWithoutSkip == y) {
System.out.println(" ");
numberOfRepetitionsWithoutSkip = 0;
} else {
if (numberOfLetter == 0) {
print(this.letter1);
} else if (numberOfLetter == 1) {
print(this.letter2);
} else {
print(this.letter3);
}
}
numberOfRepititions--;
}
numberOfLetter = (numberOfLetter + 1) % 3;
} while(rest != 0);
}
public void printEveryLetterXTimesAndSkipEveryYTimesSimple(int x, int y) {
int numberOfLetter = 0;
int repititionsAbs = 0;
while((repititionsAbs % y) != 0 || repititionsAbs == 0) {
for (int i = 0; i < x; i++) {
repititionsAbs++;
if (repititionsAbs % y == 0) {
print(' ');
continue;
}
if (numberOfLetter == 0) {
print(this.letter1);
} else if (numberOfLetter == 1) {
print(this.letter2);
} else {
print(this.letter3);
}
}
numberOfLetter = (numberOfLetter + 1) % 3;
}
}
public char getLetter2() {
return this.letter2;
}
public void setLetter2(char letter2) {
this.letter2 = letter2;
}
public int setMaxLengthOfSchema(int maxLengthOfSchema) {
this.maxLengthOfSchema = maxLengthOfSchema;
return this.maxLengthOfSchema;
}
public void setDoStillExecuteAfterMaxLength(boolean doStillExecuteAfterMaxLength) {
this.doStillExecuteAfterMaxLength = doStillExecuteAfterMaxLength;
}
public boolean allLettersAreDifferent() {
return this.letter1 != this.letter2 && this.letter1 != this.letter3 && letter2 != this.letter3;
}
public static void main(String[] args) {
AllFeaturesInOne allFeaturesInOne = new AllFeaturesInOne('d');
if (allFeaturesInOne.getLetter2() == 'd') {
allFeaturesInOne.setLetter2('i');
}
allFeaturesInOne.setMaxLengthOfSchema(1000);
//should print the fibonacci schema in chars with a space between each step and with 5 steps
allFeaturesInOne.printFibonacciSchema(true);
AllFeaturesInOne allFeaturesInOne2 = new AllFeaturesInOne(6, 'e');
allFeaturesInOne2.setDoStillExecuteAfterMaxLength(true);
//should print the fibonacci schema in chars with a space between each step and with 6 steps
// but with mul instead of sum
allFeaturesInOne2.printFibonacciButWithMultiplication();
Configuration configuration = new Configuration(10, 100, 'f', 'g', 'h', true);
AllFeaturesInOne allFeaturesInOne3 = new AllFeaturesInOne(configuration);
print(allFeaturesInOne3.allLettersAreDifferent());
// these two should print the same thing
allFeaturesInOne3.printEveryLetterXTimesAndSkipEveryYTimesComplex(13, 7);
allFeaturesInOne3.printEveryLetterXTimesAndSkipEveryYTimesSimple(13, 7);
// should print true
print(allFeaturesInOne3.configuration.getRepititionsOfSchema() == 10);
}
}

View File

@ -0,0 +1,28 @@
public class Configuration {
int repititionsOfSchema;
int maxLengthOfSchema;
char letter1;
char letter2;
char letter3;
boolean doStillExecuteAfterMaxLength;
public Configuration(
int repititionsOfSchema,
int maxLengthOfSchema,
char letter1,
char letter2,
char letter3,
boolean doStillExecuteAfterMaxLength
) {
this.repititionsOfSchema = repititionsOfSchema;
this.maxLengthOfSchema = maxLengthOfSchema;
this.letter1 = letter1;
this.letter2 = letter2;
this.letter3 = letter3;
this.doStillExecuteAfterMaxLength = doStillExecuteAfterMaxLength;
}
public int getRepititionsOfSchema() {
return this.repititionsOfSchema;
}
}