fixed bugs in TextOutput.java
This commit is contained in:
parent
94fa99d5b2
commit
70920b794a
|
@ -40,33 +40,25 @@ public class TextOutput {
|
|||
* @param text the ArrayList which is used for the output.
|
||||
*/
|
||||
private void toFormat(ArrayList<String> text) {
|
||||
int currentLength = 0;
|
||||
for (String paragraph : text) {
|
||||
int currentLength = 0;
|
||||
String[] words = paragraph.split(" ");
|
||||
int lastWordNumber = words.length;
|
||||
int currentWordNumber = 0;
|
||||
for(String word : words) {
|
||||
for (String word : words) {
|
||||
currentWordNumber++;
|
||||
if (word.length()<= columnWidth - currentLength) {
|
||||
if (word.length() <= columnWidth - currentLength) {
|
||||
System.out.print(word);
|
||||
if (!(lastWordNumber == currentWordNumber)) {
|
||||
System.out.print(" ");
|
||||
currentLength = currentLength + word.length() + 1;
|
||||
}
|
||||
else {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
System.out.println();
|
||||
currentLength = 0;
|
||||
System.out.print(word);
|
||||
if(!(currentWordNumber == lastWordNumber)) {
|
||||
System.out.print(" ");
|
||||
currentLength = word.length() + 1;
|
||||
}
|
||||
else {
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
if (!(currentWordNumber == lastWordNumber)) {
|
||||
System.out.print(" ");
|
||||
currentLength = 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.
|
||||
*/
|
||||
public boolean formatFix(int length) {
|
||||
if(length > 0) {
|
||||
if (length > 0) {
|
||||
formatRaw = false;
|
||||
columnWidth = length;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue