fixed bugs in TextOutput.java

This commit is contained in:
schrom01 2021-11-11 20:35:41 +01:00
parent 94fa99d5b2
commit 70920b794a
1 changed files with 13 additions and 22 deletions

View File

@ -40,35 +40,27 @@ public class TextOutput {
* @param text the ArrayList which is used for the output. * @param text the ArrayList which is used for the output.
*/ */
private void toFormat(ArrayList<String> text) { private void toFormat(ArrayList<String> text) {
int currentLength = 0;
for (String paragraph : text) { for (String paragraph : text) {
int currentLength = 0;
String[] words = paragraph.split(" "); String[] words = paragraph.split(" ");
int lastWordNumber = words.length; int lastWordNumber = words.length;
int currentWordNumber = 0; int currentWordNumber = 0;
for(String word : words) { for (String word : words) {
currentWordNumber++; currentWordNumber++;
if (word.length()<= columnWidth - currentLength) { if (word.length() <= columnWidth - currentLength) {
System.out.print(word); System.out.print(word);
if (!(lastWordNumber == currentWordNumber)) { } else {
System.out.println();
currentLength = 0;
System.out.print(word);
}
if (!(currentWordNumber == lastWordNumber)) {
System.out.print(" "); System.out.print(" ");
currentLength = currentLength + word.length() + 1; currentLength = currentLength + word.length() + 1;
} } else {
else {
System.out.println(); System.out.println();
} }
} }
else {
System.out.println();
System.out.print(word);
if(!(currentWordNumber == lastWordNumber)) {
System.out.print(" ");
currentLength = word.length() + 1;
}
else {
System.out.println();
}
}
}
} }
} }
@ -90,12 +82,11 @@ public class TextOutput {
* @return returns true if successful and false if and invalid length has been submitted. * @return returns true if successful and false if and invalid length has been submitted.
*/ */
public boolean formatFix(int length) { public boolean formatFix(int length) {
if(length > 0) { if (length > 0) {
formatRaw = false; formatRaw = false;
columnWidth = length; columnWidth = length;
return true; return true;
} } else {
else {
return false; return false;
} }
} }