From ae881bd8ac450d4ff19c4cc20b21b86e46b16ce1 Mon Sep 17 00:00:00 2001 From: MikeZyeman Date: Fri, 5 Nov 2021 11:10:19 +0100 Subject: [PATCH 1/3] Generated TextLogik, renamed SystemInput to TextInput --- src/SystemInput.java | 21 --------------------- src/TextEditor.java | 25 +------------------------ src/TextInput.java | 10 ++++++++++ src/TextLogik.java | 24 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 45 deletions(-) delete mode 100644 src/SystemInput.java create mode 100644 src/TextInput.java create mode 100644 src/TextLogik.java diff --git a/src/SystemInput.java b/src/SystemInput.java deleted file mode 100644 index ad1ca04..0000000 --- a/src/SystemInput.java +++ /dev/null @@ -1,21 +0,0 @@ -import java.util.Scanner; - -public class SystemInput { - - private Scanner scanner; - - public SystemInput() { - scanner = new Scanner(""); - } - - /** - * Method: CheckForInput - */ - public String[] checkForInput() { - - return new String[] { - "Test" - }; - } - -} diff --git a/src/TextEditor.java b/src/TextEditor.java index a65579e..b263df5 100644 --- a/src/TextEditor.java +++ b/src/TextEditor.java @@ -1,31 +1,8 @@ public class TextEditor { - private SystemInput sysInput; - private Text text; public static void main(String[] args) { - TextEditor t = new TextEditor(); - } - - public TextEditor() { - sysInput = new SystemInput(); - text = new Text(); - String command[]; - - do { - command = sysInput.checkForInput(); - - switch (command[0]) { - case "ADD": - break; - case "REMOVE": - break; - default: - System.out.println("Command not found. Try again"); - break; - } - - } while ("exit".equals(command[0])); + TextLogik tl = new TextLogik(); } } diff --git a/src/TextInput.java b/src/TextInput.java new file mode 100644 index 0000000..e28015d --- /dev/null +++ b/src/TextInput.java @@ -0,0 +1,10 @@ +import java.util.Scanner; + +public class TextInput { + + private static Scanner sc = new Scanner(""); + + public static String[] checkForInput() { + return sc.nextLine().split(""); + } +} diff --git a/src/TextLogik.java b/src/TextLogik.java new file mode 100644 index 0000000..3064b61 --- /dev/null +++ b/src/TextLogik.java @@ -0,0 +1,24 @@ +public class TextLogik { + private Text text; + + public TextLogik() { + text = new Text(); + String command[]; + + do { + command = TextInput.checkForInput(); + + switch (command[0]) { + case "ADD": + break; + case "REMOVE": + break; + default: + System.out.println("Command not found. Try again"); + break; + } + + } while ("exit".equals(command[0])); + } + +} From 7d256f991500ad5b7a402f67d46b5dc8c4b097e2 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Fri, 5 Nov 2021 11:35:09 +0100 Subject: [PATCH 2/3] TextTest.java added test method for txt.index methode --- src/Text.java | 50 ++++++++++++++++++++++++++++++++++++++-------- test/TextTest.java | 12 +++++------ 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/Text.java b/src/Text.java index d4b75ce..54e52e2 100644 --- a/src/Text.java +++ b/src/Text.java @@ -1,9 +1,6 @@ import java.io.File; import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Scanner; +import java.util.*; public class Text { @@ -47,6 +44,12 @@ public class Text { return true; } + /** + * Method to get all paragraph of the existing instance. + * + * @return returns a ArrayList with all text inside. + */ + public ArrayList getText() { return text; } @@ -98,6 +101,14 @@ public class Text { return true; } + /** + * This method deletes a specific Paragraph. As a Parameter it uses a int. + * If the Parameter is valid it deletes the specific Pararaph otherwise returns false + * + * @param paragraphNumber + * @return False: If the int is not a valid paragraph. + * @return True: If the int is a valid paragraph number + */ public boolean del(int paragraphNumber) { if (paragraphExists(paragraphNumber)) { @@ -107,31 +118,54 @@ public class Text { return false; } + /** + * This method deletes the last paragraph in the text Array. + * + * @return True: if paragraph has been deleted. + */ public boolean del() { text.remove(text.size() - 1); return true; } + /** + * This method creates a ArrayList. + * Every word which is used in the text more than 3 times + * will be added to the ArrayList with the paragraphes where the word is been used. + * + * @return ArrayList + */ + public ArrayList index() { wordbook = createWordlist(); ArrayList output = new ArrayList<>(); for (Map.Entry> entry : wordbook.entrySet()) { String key = entry.getKey(); ArrayList values = entry.getValue(); + String input = ""; if (values.get(0) >= 3) { - output.add(key); - for (int value : values) { - output.add(String.valueOf(value)); + input += key + " "; + for (int i = 1; i < values.size(); i++) { + input += values.get(i) + ", "; } + output.add(input); } } return output; } + /** + * This method counts all Words in text and adds them together with the paragraph where the word is been used to a Hashmap. + * + * @return HashMap> + */ private HashMap> createWordlist() { for (int i = 0; i < text.size(); i++) { String[] woerter = text.get(i).trim().toLowerCase().split("[ :;.,!?><\'/]+"); for (String wort : woerter) { + String firstLetter = wort.substring(0,1); + String restLetters = wort.substring(1); + wort = firstLetter.toUpperCase()+restLetters; ArrayList zahlenListe; int zähler = 1; if (wordbook.containsKey(wort)) { @@ -147,7 +181,7 @@ public class Text { } else { zahlenListe = new ArrayList<>(); zahlenListe.add(1); - zahlenListe.add(zähler); + zahlenListe.add(i + 1); wordbook.put(wort, zahlenListe); } } diff --git a/test/TextTest.java b/test/TextTest.java index 5c6b081..46a5d13 100644 --- a/test/TextTest.java +++ b/test/TextTest.java @@ -1,25 +1,25 @@ +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.HashMap; -import java.util.Map; public class TextTest { Text txt; - HashMap> hMap; ArrayList sListe; @BeforeEach void setup() { txt = new Text(); - hMap = new HashMap<>(); - sListe = new ArrayList<>(); - sListe.add("Hallo hallo zusammen"); - sListe.add("Hallo wie gehts"); } @Test void indexTest() { + txt.add("Hallo Hallo zusammen !test!"); + txt.add("Hallo, wie zusammen"); + txt.add("Hallo,wie wie zusammen"); + sListe= txt.index(); + Assertions.assertEquals("Hallo 1, 2, 3, ",sListe.get(0)); } } From 9a05956582e1e94a404a6bdada673769868f05d9 Mon Sep 17 00:00:00 2001 From: Andrin Fassbind Date: Fri, 5 Nov 2021 11:41:10 +0100 Subject: [PATCH 3/3] Text.java method index changed output format --- src/Text.java | 8 ++++++-- test/TextTest.java | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Text.java b/src/Text.java index 54e52e2..35ba03e 100644 --- a/src/Text.java +++ b/src/Text.java @@ -144,9 +144,13 @@ public class Text { ArrayList values = entry.getValue(); String input = ""; if (values.get(0) >= 3) { - input += key + " "; + input += key + " "; for (int i = 1; i < values.size(); i++) { - input += values.get(i) + ", "; + if(i+1 == values.size()){ + input += values.get(i)+""; + }else { + input += values.get(i) + ", "; + } } output.add(input); } diff --git a/test/TextTest.java b/test/TextTest.java index 46a5d13..d7e78b1 100644 --- a/test/TextTest.java +++ b/test/TextTest.java @@ -20,6 +20,6 @@ public class TextTest { txt.add("Hallo, wie zusammen"); txt.add("Hallo,wie wie zusammen"); sListe= txt.index(); - Assertions.assertEquals("Hallo 1, 2, 3, ",sListe.get(0)); + Assertions.assertEquals("Hallo 1, 2, 3",sListe.get(0)); } }