Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SystemOut {
|
||||
private boolean formatRaw;
|
||||
private int columnWidth;
|
||||
|
||||
public void print(ArrayList text) {
|
||||
if (formatRaw) {
|
||||
for(int counter = 0; counter < text.size(); counter++) {
|
||||
System.out.println("<" + counter + ">: <" + text.get(counter) + ">");
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void formatRaw() {
|
||||
formatRaw = true;
|
||||
}
|
||||
|
||||
public void formatFix(int length) {
|
||||
formatRaw = false;
|
||||
columnWidth = length;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TextOutput {
|
||||
private boolean formatRaw;
|
||||
private int columnWidth;
|
||||
|
||||
public void print(ArrayList<String> text) {
|
||||
if (formatRaw) {
|
||||
for (int counter = 0; counter < text.size(); counter++) {
|
||||
System.out.println("<" + (counter + 1) + ">: <" + text.get(counter) + ">");
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (String paragraph : text) {
|
||||
String[] words = paragraph.split(" ");
|
||||
int currentLength = 0;
|
||||
for(String word: words) {
|
||||
if(word.length() > columnWidth){
|
||||
String[] letters = word.split("");
|
||||
int letterLenght = letters.length;
|
||||
int lettersPrinted = 0;
|
||||
do{
|
||||
System.out.println();
|
||||
currentLength = 0;
|
||||
for(int i=0; i< columnWidth; i++) {
|
||||
if(letterLenght > 0) {
|
||||
System.out.print(letters[lettersPrinted]);
|
||||
letterLenght--;
|
||||
lettersPrinted++;
|
||||
currentLength++;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (letterLenght>columnWidth);
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
if(word.length() >= columnWidth - currentLength){
|
||||
System.out.println();
|
||||
currentLength = 0;
|
||||
}
|
||||
System.out.print(word + " ");
|
||||
currentLength += word.length() + 1;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void formatRaw() {
|
||||
formatRaw = true;
|
||||
}
|
||||
|
||||
public void formatFix(int length) {
|
||||
formatRaw = false;
|
||||
columnWidth = length;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user