diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 814571d..ec43567 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,7 +1,17 @@
-
+
+
+
+
+
+
+
+
+
+
+
@@ -26,8 +36,18 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -36,8 +56,8 @@
-
-
+
+
@@ -48,15 +68,9 @@
-
-
-
-
-
-
-
-
-
+
+
+
@@ -64,11 +78,11 @@
-
-
+
+
-
-
+
+
@@ -83,6 +97,9 @@
+
+
+
@@ -605,15 +622,17 @@
+
+
-
+
-
+
@@ -664,6 +683,80 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -690,45 +783,47 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
diff --git a/out/production/Textanalyse/com/structix/Analyse.class b/out/production/Textanalyse/com/structix/Analyse.class
index 4b47a6f..f069993 100644
Binary files a/out/production/Textanalyse/com/structix/Analyse.class and b/out/production/Textanalyse/com/structix/Analyse.class differ
diff --git a/out/production/Textanalyse/com/structix/Main.class b/out/production/Textanalyse/com/structix/Main.class
index 76b53ad..8e17c54 100644
Binary files a/out/production/Textanalyse/com/structix/Main.class and b/out/production/Textanalyse/com/structix/Main.class differ
diff --git a/out/production/Textanalyse/com/structix/Menu.class b/out/production/Textanalyse/com/structix/Menu.class
index e29bef8..d1e3df2 100644
Binary files a/out/production/Textanalyse/com/structix/Menu.class and b/out/production/Textanalyse/com/structix/Menu.class differ
diff --git a/out/production/Textanalyse/com/structix/Menubuilder.class b/out/production/Textanalyse/com/structix/Menubuilder.class
index 161c6ec..0d8da6d 100644
Binary files a/out/production/Textanalyse/com/structix/Menubuilder.class and b/out/production/Textanalyse/com/structix/Menubuilder.class differ
diff --git a/src/com/structix/Analyse.java b/src/com/structix/Analyse.java
index 0843a99..8623b8c 100644
--- a/src/com/structix/Analyse.java
+++ b/src/com/structix/Analyse.java
@@ -18,6 +18,10 @@ public class Analyse {
public Analyse(String dateipfad) {
inhalt = dateilesen(dateipfad);
textAnpassen();
+
+ //Initialisierung der globalen Variablen
+ verschiedenWoerter();
+ haeufigkeit();
}
@@ -86,15 +90,34 @@ public class Analyse {
}
}
}
- String ausgabe = "";
- for (int i = 0; i < anzahl.length; i++) {
- ausgabe += einzelneWoerter[i] + ": " + anzahl[i] + "\n";
- }
- return ausgabe;
+ return sortieren(einzelneWoerter, anzahl);
}
public String textausgabe() {
return inhalt;
}
+
+ private String sortieren(String woerter[], int anz[]) {
+ String tempstring;
+ int tempint;
+ for (int i = 1; i < woerter.length; i++) {
+ for (int z = 0; z < anz.length - i; z++) {
+ if (anz[z] < anz[z + 1]) {
+ tempint = anz[z];
+ anz[z] = anz[z + 1];
+ anz[z + 1] = tempint;
+ tempstring = woerter[z];
+ woerter[z] = woerter[z + 1];
+ woerter[z + 1] = tempstring;
+ }
+ }
+ }
+ String ausgabe = "";
+ for (int i = 0; i < anz.length; i++) {
+ ausgabe += woerter[i] + ": " + anz[i] + "\n";
+ }
+ return ausgabe;
+ }
+
}
diff --git a/src/com/structix/Main.java b/src/com/structix/Main.java
index 2a0f0d8..6058ee2 100644
--- a/src/com/structix/Main.java
+++ b/src/com/structix/Main.java
@@ -12,13 +12,15 @@ package com.structix;
/* Bearbeitungszeit
* 14.05.16: 13:04 - 14:08 Uhr
* 15.05.16: 20:41 - 21:38 Uhr
+ * 16.05.16: 20:47 - 21:44 Uhr
*/
public class Main {
public static void main(String[] args) {
Menu m = new Menu();
- m.dateipfad();
+ m.debug();
+ //m.dateipfad();
while (!m.hauptmenu());
}
}
diff --git a/src/com/structix/Menu.java b/src/com/structix/Menu.java
index 0dd0bb4..6784026 100644
--- a/src/com/structix/Menu.java
+++ b/src/com/structix/Menu.java
@@ -11,6 +11,12 @@ public class Menu {
Analyse an;
+ public void debug() {
+ an = new Analyse("Test.txt");
+ }
+
+
+
public void dateipfad() {
System.out.println("Geben Sie einen Dateipfad an (relativ sowie absolut erlaubt): ");
Scanner eingabe = new Scanner(System.in);
@@ -20,7 +26,7 @@ public class Menu {
public boolean hauptmenu() {
boolean exit = false;
int auswahl = 0;
- auswahl = mbuilder.menuAnzeigen(new String[]{"Anzahl der Wörter", "Anzahl der verschiedenen Wörter", "Häufigkeit der verschiedene Wörter"});
+ auswahl = mbuilder.menuAnzeigen(new String[]{"Anzahl der Wörter", "Anzahl der verschiedenen Wörter", "Häufigkeit der verschiedene Wörter"}, "|");
switch (auswahl) {
case 1:
ausgabe("Anzahl der Wörter: " + an.laenge());
diff --git a/src/com/structix/Menubuilder.java b/src/com/structix/Menubuilder.java
index d132e8b..903eb8e 100644
--- a/src/com/structix/Menubuilder.java
+++ b/src/com/structix/Menubuilder.java
@@ -1,6 +1,5 @@
package com.structix;
-import java.util.InputMismatchException;
import java.util.Scanner;
/**
@@ -15,19 +14,59 @@ public class Menubuilder {
ueberschrift = title;
}
- public int menuAnzeigen(String items[]) {
-
+ public int menuAnzeigen(String items[], String randzeichen) {
+ int maxlaenge = maximalwert(items);
+ int spaces;
+ String spacesString;
String ausgabe = "";
- ausgabe += ueberschrift + "\n";
+ //---Trennstrich generieren---
+ String trennstrich = randzeichen;
+ for (int i = 0; i < maxlaenge + 1; i++) {
+ trennstrich += "-";
+ }
+ trennstrich += randzeichen;
+ ausgabe += trennstrich + "\n";
+ //---Trennstrich generieren---
+
+ //---Überschrift---
+ ausgabe += randzeichen + ueberschrift;
+ spaces = maxlaenge - ueberschrift.length();
+ spacesString = "";
+ for (int i = 0; i <= spaces; i++) {
+ spacesString += " ";
+ }
+ ausgabe += spacesString + randzeichen + "\n";
+ //---Überschrift---
+
+ //---Menüeinträge---
int eing = 0;
for (int i = 0; i < items.length; i++) {
- ausgabe += items[i] + ": (" + (i + 1) + ")\n";
+ spaces = (maxlaenge - 4 + (items.length / 10)) - items[i].length();
+ spacesString = "";
+ for (int z = 0; z < spaces; z++) {
+ spacesString += " ";
+ }
+ ausgabe += randzeichen + items[i] + ": (" + (i + 1) + ")" + spacesString + randzeichen + "\n";
}
- ausgabe += "Exit (" + (items.length + 1) + ")\n";
+
+ //---Exit Eintrag---
+ spaces = (maxlaenge - 4 + (items.length / 10)) - "Exit".length();
+ spacesString = "";
+ for (int z = 0; z <= spaces; z++) {
+ spacesString += " ";
+ }
+ ausgabe += randzeichen + "Exit (" + (items.length + 1) + ")" + spacesString + randzeichen + "\n";
+ System.out.print(ausgabe);
+ //---Exit Eintrag---
+ //---Menüeinträge---
+
+ //---Abfrage---
do {
- System.out.print(ausgabe + "\nEingabe: ");
+ System.out.print(randzeichen + "Eingabe: ");
eing = eingabeInt();
} while (eing <= 0 || eing > items.length + 1);
+ System.out.println(trennstrich);
+ //---Abfrage---
return eing;
}
@@ -46,5 +85,22 @@ public class Menubuilder {
return input;
}
+ private int maximalwert(String items[]) {
+ int itemlaenge[] = new int[items.length];
+ for (int i = 0; i < items.length; i++) {
+ itemlaenge[i] = items[i].length();
+ }
+ int tempint;
+ for (int i = 1; i < itemlaenge.length; i++) {
+ for (int z = 0; z < itemlaenge.length - i; z++) {
+ if (itemlaenge[z] < itemlaenge[z + 1]) {
+ tempint = itemlaenge[z];
+ itemlaenge[z] = itemlaenge[z + 1];
+ itemlaenge[z + 1] = tempint;
+ }
+ }
+ }
+ return itemlaenge[0] + 4 + (items.length / 10);
+ }
}