From 70920b794a6d02406406fdeb17cc24979b3f785b Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 11 Nov 2021 20:35:41 +0100 Subject: [PATCH] fixed bugs in TextOutput.java --- src/TextOutput.java | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) 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; } }