From 5369a164978cd3f2db4f5d51a19e8fcc354594f8 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Mon, 8 Nov 2021 12:47:02 +0100 Subject: [PATCH 1/2] created Dictionary docs --- Kick-off.md => docs/Kick-off.md | 0 PM2_ClassDiagram.drawio => docs/PM2_ClassDiagram.drawio | 0 Pflichtenheft.md => docs/Pflichtenheft.md | 0 README.md => docs/README.md | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename Kick-off.md => docs/Kick-off.md (100%) rename PM2_ClassDiagram.drawio => docs/PM2_ClassDiagram.drawio (100%) rename Pflichtenheft.md => docs/Pflichtenheft.md (100%) rename README.md => docs/README.md (100%) diff --git a/Kick-off.md b/docs/Kick-off.md similarity index 100% rename from Kick-off.md rename to docs/Kick-off.md diff --git a/PM2_ClassDiagram.drawio b/docs/PM2_ClassDiagram.drawio similarity index 100% rename from PM2_ClassDiagram.drawio rename to docs/PM2_ClassDiagram.drawio diff --git a/Pflichtenheft.md b/docs/Pflichtenheft.md similarity index 100% rename from Pflichtenheft.md rename to docs/Pflichtenheft.md diff --git a/README.md b/docs/README.md similarity index 100% rename from README.md rename to docs/README.md From 5d4b9114a024b4ebd2b56b0572eee1ad9841fd8a Mon Sep 17 00:00:00 2001 From: MikeZyeman Date: Mon, 8 Nov 2021 20:45:44 +0100 Subject: [PATCH 2/2] Implemented functional ADD, FORMAT and PRINT feature. Reformat code in several files --- src/TextInput.java | 8 ++++++-- src/TextLogik.java | 35 +++++++++++++++++++++++++++++++---- src/TextOutput.java | 14 +++++++------- test/SystemInputTest.java | 2 -- test/TextEditorTest.java | 2 -- test/TextInputTest.java | 10 ++++++++++ test/TextOutputTest.java | 13 +++---------- 7 files changed, 57 insertions(+), 27 deletions(-) delete mode 100644 test/SystemInputTest.java delete mode 100644 test/TextEditorTest.java create mode 100644 test/TextInputTest.java diff --git a/src/TextInput.java b/src/TextInput.java index 61192dd..d4abab5 100644 --- a/src/TextInput.java +++ b/src/TextInput.java @@ -2,9 +2,13 @@ import java.util.Scanner; public class TextInput { - private static final Scanner sc = new Scanner(""); + private static final Scanner sc = new Scanner(System.in); public static String[] checkForInput() { - return sc.nextLine().split(""); + return sc.nextLine().split(" "); + } + + public static String getTextInput() { + return sc.nextLine(); } } diff --git a/src/TextLogik.java b/src/TextLogik.java index 58b1ef7..aea3198 100644 --- a/src/TextLogik.java +++ b/src/TextLogik.java @@ -2,9 +2,11 @@ import java.util.ArrayList; public class TextLogik { private final Text text; + private final TextOutput textOutput; public TextLogik() { text = new Text(); + textOutput = new TextOutput(); String[] command; do { @@ -12,22 +14,43 @@ public class TextLogik { switch (command[0]) { case "ADD": + + if (command.length == 1) { + text.add(TextInput.getTextInput()); + } else if (isNumeric(command[1])) { + int line = Integer.parseInt(command[1]); + + text.add(line, TextInput.getTextInput()); + } else { + textOutput.errorInvalidCommand(); + } + break; case "DEL": + // TODO Hier Delete Funktion hinzufügen. break; case "Dummy": text.dummy(); break; case "EXIT": break; - case "FORMAT RAW": - break; - case "FORMAT FIX": + case "FORMAT": + if (command.length > 1 && "RAW".equals(command[1])) { + textOutput.formatRaw(); + } else if (command.length > 2 && "FIX".equals(command[1]) && isNumeric(command[2])) { + textOutput.formatFix(Integer.parseInt(command[2])); + } else { + textOutput.errorInvalidCommand(); + } + break; case "INDEX": ArrayList Index = text.index(); break; case "PRINT": + + textOutput.print(text.getText()); + break; case "REPLACE": break; @@ -36,7 +59,11 @@ public class TextLogik { break; } - } while ("EXIT".equals(command[0])); + } while (!"EXIT".equals(command[0])); + } + + private boolean isNumeric(String str) { + return str.matches("\\d+"); } } diff --git a/src/TextOutput.java b/src/TextOutput.java index f9ccee9..6e957eb 100644 --- a/src/TextOutput.java +++ b/src/TextOutput.java @@ -7,8 +7,7 @@ public class TextOutput { public void print(ArrayList text) { if (formatRaw) { printFormated(text); - } - else { + } else { printUnformated(text); } } @@ -19,6 +18,7 @@ public class TextOutput { } } + private void printUnformated(ArrayList text) { for (String paragraph : text) { String[] words = paragraph.split(" "); @@ -39,14 +39,13 @@ public class TextOutput { currentLength++; } } - if(!(letterLenght == 0)){ + if (!(letterLenght == 0)) { System.out.println(); } } while (letterLenght >= columnWidth); - } - else { + } else { if (word.length() >= columnWidth - currentLength) { currentLength = 0; System.out.println(); @@ -64,9 +63,10 @@ public class TextOutput { } public void formatFix(int length) { - formatRaw = false; - columnWidth = length; + formatRaw = false; + columnWidth = length; } + public void errorInvalidString() { System.err.println("Invalid String"); } diff --git a/test/SystemInputTest.java b/test/SystemInputTest.java deleted file mode 100644 index 9f9b8af..0000000 --- a/test/SystemInputTest.java +++ /dev/null @@ -1,2 +0,0 @@ -public class SystemInputTest { -} diff --git a/test/TextEditorTest.java b/test/TextEditorTest.java deleted file mode 100644 index 9e3bd87..0000000 --- a/test/TextEditorTest.java +++ /dev/null @@ -1,2 +0,0 @@ -public class TextEditorTest { -} diff --git a/test/TextInputTest.java b/test/TextInputTest.java new file mode 100644 index 0000000..10c5df2 --- /dev/null +++ b/test/TextInputTest.java @@ -0,0 +1,10 @@ +import org.junit.jupiter.api.Test; + +class TextInputTest { + + @Test + public void inputTest() { + + } + +} \ No newline at end of file diff --git a/test/TextOutputTest.java b/test/TextOutputTest.java index 341cd8f..0e007ce 100644 --- a/test/TextOutputTest.java +++ b/test/TextOutputTest.java @@ -1,18 +1,14 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import javax.swing.*; - import java.util.ArrayList; -import static org.junit.jupiter.api.Assertions.*; - class TextOutputTest { TextOutput textOutput; ArrayList text; @BeforeEach - public void setup(){ + public void setup() { textOutput = new TextOutput(); textOutput.formatFix(9); textOutput.formatRaw(); @@ -25,10 +21,7 @@ class TextOutputTest { } @Test - public void print(){ - textOutput.print(text); - + public void print() { + textOutput.print(text); } - - } \ No newline at end of file