diff --git a/Pflichtenheft.md b/Pflichtenheft.md index 226e788..7ef16b0 100644 --- a/Pflichtenheft.md +++ b/Pflichtenheft.md @@ -79,35 +79,39 @@ In der Grundfunktionalität sieht sie folgendermassen aus: ```java import java.util.Scanner; + /** -* Vereinfachte Demonstration Scanner-Funktion für Konsole * Modifiziert von BlueJ InputReader.java -* https://bluej.org/objects-first/resources/projects.zip * @author Für die Anpassungen: berp -* @version 2019-10-27 -*/ + * Vereinfachte Demonstration Scanner-Funktion für Konsole * Modifiziert von BlueJ InputReader.java + * https://bluej.org/objects-first/resources/projects.zip * @author Für die Anpassungen: berp + * @version 2019-10-27 + */ public class InputReaderMod { - private Scanner scanner; - /** - * Main-Methode - * @param args Eingabe vom Typ String - */ - public static void main(String[] args) { - InputReaderMod reader = new InputReaderMod(); System.out.print("Please enter your input: "); System.out.print("Input was: "+reader.getInput()+"\n"); - } + private final Scanner scanner; - /** - * Konstruktor erzeugt Objekt vom Typ Scanner - */ - public InputReaderMod() { - scanner = new Scanner(System.in); - } + /** + * Main-Methode + * @param args Eingabe vom Typ String + */ + public static void main(String[] args) { + InputReaderMod reader = new InputReaderMod(); + System.out.print("Please enter your input: "); + System.out.print("Input was: " + reader.getInput() + "\n"); + } - /** - * Lies Eingabezeile - * @return Eingabezeile - */ - public String getInput() { - return scanner.nextLine(); - } + /** + * Konstruktor erzeugt Objekt vom Typ Scanner + */ + public InputReaderMod() { + scanner = new Scanner(System.in); + } + + /** + * Lies Eingabezeile + * @return Eingabezeile + */ + public String getInput() { + return scanner.nextLine(); + } } ``` diff --git a/src/Text.java b/src/Text.java index 35ba03e..1988e2b 100644 --- a/src/Text.java +++ b/src/Text.java @@ -4,7 +4,7 @@ import java.util.*; public class Text { - private ArrayList text = new ArrayList<>(); + private final ArrayList text = new ArrayList<>(); private static final String dummyText = "The standard Lorem Ipsum passage, used since the 1500s \"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.\" Section 1.10.32 of \"de Finibus Bonorum et Malorum\", written by Cicero in 45 BC \"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"; private HashMap> wordbook = new HashMap<>(); @@ -165,7 +165,7 @@ public class Text { */ private HashMap> createWordlist() { for (int i = 0; i < text.size(); i++) { - String[] woerter = text.get(i).trim().toLowerCase().split("[ :;.,!?><\'/]+"); + String[] woerter = text.get(i).trim().toLowerCase().split("[ :;.,!?><'/]+"); for (String wort : woerter) { String firstLetter = wort.substring(0,1); String restLetters = wort.substring(1); diff --git a/src/TextInput.java b/src/TextInput.java index e28015d..61192dd 100644 --- a/src/TextInput.java +++ b/src/TextInput.java @@ -2,7 +2,7 @@ import java.util.Scanner; public class TextInput { - private static Scanner sc = new Scanner(""); + private static final Scanner sc = new Scanner(""); public static String[] checkForInput() { return sc.nextLine().split(""); diff --git a/src/TextLogik.java b/src/TextLogik.java index 3064b61..5084cf3 100644 --- a/src/TextLogik.java +++ b/src/TextLogik.java @@ -1,9 +1,9 @@ public class TextLogik { - private Text text; + private final Text text; public TextLogik() { text = new Text(); - String command[]; + String[] command; do { command = TextInput.checkForInput(); diff --git a/src/TextOutput.java b/src/TextOutput.java index e049478..2a1ebe3 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -2,28 +2,37 @@ import java.util.ArrayList; public class TextOutput { private boolean formatRaw; - private int columnWidth; + private int columnWidth = 10; public void print(ArrayList text) { - if (formatRaw) { + if (formatRaw) { + printFormated(text); + } + else { + printUnformated(text); + } + } + + private void printFormated(ArrayList text) { for (int counter = 0; counter < text.size(); counter++) { System.out.println("<" + (counter + 1) + ">: <" + text.get(counter) + ">"); } + } - else { + private void printUnformated(ArrayList text) { for (String paragraph : text) { String[] words = paragraph.split(" "); int currentLength = 0; - for(String word: words) { - if(word.length() > columnWidth){ + for (String word : words) { + if (word.length() > columnWidth) { String[] letters = word.split(""); int letterLenght = letters.length; int lettersPrinted = 0; - do{ + do { System.out.println(); currentLength = 0; - for(int i=0; i< columnWidth; i++) { - if(letterLenght > 0) { + for (int i = 0; i < columnWidth; i++) { + if (letterLenght > 0) { System.out.print(letters[lettersPrinted]); letterLenght--; lettersPrinted++; @@ -31,30 +40,20 @@ public class TextOutput { } } } - while (letterLenght>columnWidth); + while (letterLenght > columnWidth); } - else { - if(word.length() >= columnWidth - currentLength){ - System.out.println(); + if (word.length() >= columnWidth - currentLength) { currentLength = 0; + System.out.println(); } System.out.print(word + " "); currentLength += word.length() + 1; - - - - } + if(words.length == word } - - - - - } } - } public void formatRaw() { formatRaw = true; @@ -64,4 +63,11 @@ public class TextOutput { formatRaw = false; columnWidth = length; } + public void errorInvalidString() { + System.err.println("Invalid String"); + } + + public void errorInvalidCommand() { + System.err.println("Invalid Command"); + } } diff --git a/test/TextOutputTest.java b/test/TextOutputTest.java index f7dd6b4..e7f03aa 100644 --- a/test/TextOutputTest.java +++ b/test/TextOutputTest.java @@ -17,8 +17,9 @@ class TextOutputTest { textOutput.formatFix(9); //textOutput.formatRaw(); text = new ArrayList<>(); - text.add("123 45678 "); - text.add("123456789"); + text.add("1234 12345"); + text.add("1234"); + text.add("12 12 12"); text.add("TextTextTextTextTextTextTextTextTextTextTextTextTextText TextTextTextTextTextTextTextTextTextTextTextText TextTextText"); } @@ -27,4 +28,6 @@ class TextOutputTest { textOutput.print(text); } + + } \ No newline at end of file