diff --git a/src/TextOutput.java b/src/TextOutput.java index 06f863b..765ba5e 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -40,33 +40,25 @@ public class TextOutput { * @param text the ArrayList which is used for the output. */ private void toFormat(ArrayList 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; } }