This Kotlin program is designed to analyze a list of German words and filter them based on user input. The program reads a dictionary file and allows the user to filter words that start with a specific letter at a given position.
-
Initialization: The program initializes by loading a dictionary file (
german.dic
) located in thegerman
resource folder. The dictionary file is read and stored as a list of strings. -
User Interaction: The program continuously interacts with the user through the command line, prompting for input until the user decides to exit.
-
Input Handling:
- The user is asked to input a single letter (case-sensitive).
- The user is then asked to input a position (number) where the letter should appear in the words.
-
Filtering:
- If the position is
0
, the program filters words that start with the specified letter. - If a specific position is provided, the program filters words where the specified letter appears at the given position.
- If the position is
-
Output:
- The program displays the number of words that match the criteria.
- The user is then asked if they want to see the list of filtered words.
- If the user chooses to see the words, they are printed on the screen.
-
Loop: The program repeats the process until the user types "exit" to quit.
-
The program prompts the user to type a letter:
Please type a letter (case sensitive) or exit to quit:
-
The user inputs a letter, e.g.,
a
. -
The program then asks for a position:
Please type a number (position):
-
The user inputs a position, e.g.,
1
. -
The program filters the dictionary and displays the number of words that match the criteria:
There are X words starting with a at position 1
-
The user is asked if they want to see the words:
Do you want to see the words? (y/n)
-
If the user inputs
y
, the program prints the list of filtered words. -
The process repeats until the user types
exit
.
The dictionary file (german.dic
) should be placed in the resources/german
directory. The file should contain a list of German words, one word per line.
To run the program, execute the main
function in the Main.kt
file using a Kotlin-compatible IDE or command-line tool.
- The program expects the dictionary file to be encoded in
ISO_8859_1
. - The position input by the user is 1-based, meaning
1
refers to the first character of the word. This was to make this program more accessible to researches not familiar with 0-based indexing.