Added JavaDocs, changed some formatting
This commit is contained in:
+14
-11
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user