Added JavaDocs, changed some formatting

This commit is contained in:
Leonardo Brandenberger
2021-11-09 20:54:54 +01:00
parent e96f492386
commit e2261dc2f4
2 changed files with 24 additions and 18 deletions
+14 -11
View File
@@ -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<String> 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<String> 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();
}