Eine Methode hinzugefügt mit der ich Wörter nachschlagen kann

main
HausCook 2026-11-16 09:23:50 +01:00
parent 36fe58154e
commit 5a1ed6a026
2 changed files with 18 additions and 3 deletions

View File

@ -42,4 +42,12 @@ public class Analyser {
}
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;
}
}

View File

@ -22,9 +22,10 @@ public class Main {
IO.println("1: Total Word Count");
IO.println("2: All Words and their Frequency");
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) {
case "1" -> {
@ -36,7 +37,13 @@ public class Main {
String[] frequentWords = Analyser.frequentWords(uniqueWords, wordCounts);
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.");
}
}