Eine Methode hinzugefügt mit der ich Wörter nachschlagen kann
parent
36fe58154e
commit
5a1ed6a026
|
|
@ -42,4 +42,12 @@ public class Analyser {
|
||||||
}
|
}
|
||||||
return frequentWords;
|
return frequentWords;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int searchWord(ArrayList<String> uniqueWordList, ArrayList<Integer> wordCounts, String target) {
|
||||||
|
int index = uniqueWordList.indexOf(target);
|
||||||
|
if (index != -1) {
|
||||||
|
return wordCounts.get(index);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -22,9 +22,10 @@ public class Main {
|
||||||
IO.println("1: Total Word Count");
|
IO.println("1: Total Word Count");
|
||||||
IO.println("2: All Words and their Frequency");
|
IO.println("2: All Words and their Frequency");
|
||||||
IO.println("3: Top 10 Words");
|
IO.println("3: Top 10 Words");
|
||||||
IO.println("4: Exit");
|
IO.println("4: Look up Word:");
|
||||||
|
IO.println("5: Exit");
|
||||||
|
|
||||||
String choice = IO.readln("Pick a Number [1. |2. |3. |4. ]");
|
String choice = IO.readln("Pick a Number [1. |2. |3. |4. |5. ]");
|
||||||
|
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case "1" -> {
|
case "1" -> {
|
||||||
|
|
@ -36,7 +37,13 @@ public class Main {
|
||||||
String[] frequentWords = Analyser.frequentWords(uniqueWords, wordCounts);
|
String[] frequentWords = Analyser.frequentWords(uniqueWords, wordCounts);
|
||||||
printFrequentWords(frequentWords);
|
printFrequentWords(frequentWords);
|
||||||
}
|
}
|
||||||
case "4" -> running = false;
|
|
||||||
|
case "4" -> {
|
||||||
|
String neededWord = IO.readln("Which Word do you want to look up?:");
|
||||||
|
int foundWordCount = Analyser.searchWord(uniqueWords, wordCounts, neededWord);
|
||||||
|
IO.println("The word " + neededWord + " appeared " + foundWordCount + " Times");
|
||||||
|
}
|
||||||
|
case "5" -> running = false;
|
||||||
default -> IO.println("Ungueltige Eingabe.");
|
default -> IO.println("Ungueltige Eingabe.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue