From e2261dc2f41d67f9db85e5fa2140e1ef22cd61f7 Mon Sep 17 00:00:00 2001 From: Leonardo Brandenberger Date: Tue, 9 Nov 2021 20:54:54 +0100 Subject: [PATCH] Added JavaDocs, changed some formatting --- src/TextOutput.java | 25 ++++++++++++++----------- test/TextOutputTest.java | 17 ++++++++++------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/TextOutput.java b/src/TextOutput.java index 91fde26..d3015c2 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -1,12 +1,15 @@ import java.util.ArrayList; - +/** + * + */ public class TextOutput { private boolean formatRaw; private int columnWidth = 10; /** - * Method which checks in which way the paragraphs should be displayed. And then + * Method which checks in which way the paragraphs should be displayed. And then calls the corresponding + * method to output the text as desired. * * @param text the ArrayList which is then formatted into the desired output. */ @@ -30,12 +33,6 @@ public class TextOutput { } - /** - * Method to print out the paragraphs with the length taken from columnWidth and adding leftover words to the next - * paragraph. - * - * @param text the ArrayList which is used for the output. - */ private void toFormatold(ArrayList text) { for (String paragraph : text) { String[] words = paragraph.split(" "); @@ -73,17 +70,23 @@ public class TextOutput { System.out.println(); //added } } + /** + * Method to print out the paragraphs with the length taken from columnWidth and adding leftover words to the next + * paragraph. + * + * @param text the ArrayList which is used for the output. + */ private void toFormat(ArrayList text) { int currentLength = 0; for (String paragraph : text) { String[] words = paragraph.split(" "); - int lastwordNumber = words.length; + int lastWordNumber = words.length; int currentWordNumber = 0; for(String word : words) { currentWordNumber++; if (word.length()<= columnWidth - currentLength) { System.out.print(word); - if (!(lastwordNumber == currentWordNumber)) { + if (!(lastWordNumber == currentWordNumber)) { System.out.print(" "); currentLength = currentLength + word.length() + 1; } @@ -94,7 +97,7 @@ public class TextOutput { else { System.out.println(); System.out.print(word); - if(!(currentWordNumber == lastwordNumber)) { + if(!(currentWordNumber == lastWordNumber)) { System.out.print(" "); currentLength = word.length(); } diff --git a/test/TextOutputTest.java b/test/TextOutputTest.java index a06bb71..7aa6658 100644 --- a/test/TextOutputTest.java +++ b/test/TextOutputTest.java @@ -1,6 +1,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; + import java.util.ArrayList; class TextOutputTest { @@ -10,15 +11,17 @@ class TextOutputTest { @BeforeEach public void setup() { textOutput = new TextOutput(); - textOutput.formatFix(9); + textOutput.formatFix(20); //textOutput.formatRaw(); text = new ArrayList<>(); - text.add("123456789"); - text.add("1234"); - text.add("12 12 12 12 12 12"); - text.add(" "); - text.add("1eeeeeee8597389751"); - text.add("TextTextTextTextTextTextTextTextTextTextTextTextTextText TextTextTextTextTextTextTextTextTextTextTextText TextTextText"); + text.add("Virtute praecedunt, quod fere cotidianis proeliis cum Germanis contendunt, septentr ionesimmensoslongusw ordos."); + text.add("Virtutedasjdhashdkjhakjdhakdshjkashd praecedunt, quod fere cotidianis proeliis cum"); + //text.add("ordos."); + //text.add("1234"); + text.add("12417575147517845 445264565"); + text.add(" "); + //text.add("1eeeeeee8597389751"); + //text.add("TextTextTextTextTextTextTextTextTextTextTextTextTextText TextTextTextTextTextTextTextTextTextTextTextText TextTextText"); } @Test