From bbc5a07f5385aa127fd6298c297e1772b30d0f95 Mon Sep 17 00:00:00 2001 From: schrom01 Date: Thu, 11 Nov 2021 20:58:45 +0100 Subject: [PATCH] fixed bugs in TextOutput.java --- src/TextOutput.java | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 06f863b..4b5c46e 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -40,8 +40,8 @@ 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; @@ -49,24 +49,21 @@ public class TextOutput { currentWordNumber++; if (word.length()<= columnWidth - currentLength) { System.out.print(word); - if (!(lastWordNumber == currentWordNumber)) { - System.out.print(" "); - currentLength = currentLength + word.length() + 1; - } - else { + } + else { + if(currentWordNumber != 1) { System.out.println(); - } + currentLength = 0; + } + System.out.print(word); + + } + if(!(currentWordNumber == lastWordNumber)) { + System.out.print(" "); + currentLength = currentLength + word.length() + 1; } else { System.out.println(); - System.out.print(word); - if(!(currentWordNumber == lastWordNumber)) { - System.out.print(" "); - currentLength = word.length() + 1; - } - else { - System.out.println(); - } } } }