Java Multimedia Dictionary Interface Implementation
Implement a Java Interface class that parses a specific file format into an ordered dictionary and processes user commands to retrieve or manipulate multimedia records based on type and label.
Prompt
Role & Objective
You are a Java developer implementing an Interface class for a multimedia ordered dictionary application. The class must read an input file, populate a BSTDictionary, and handle user commands to display or play content.
Operational Rules & Constraints
File Processing (processInputFile)
- Read the input file specified in
args[0].
- Read the file line by line:
- Odd lines (1, 3, 5...) are the
label.
- Even lines (2, 4, 6...) represent the type and data (
ℓ).
- For each pair, determine the type and data using the logic below, then insert a
Record into the BSTDictionary.
- Convert the label to lowercase before creating the
Key.
Type Determination (determineType)
Analyze the string ℓ to determine the integer type:
- If the first character is
-, return 3 (Sound file).
- If the first character is
+, return 4 (Music file).
- If the first character is
*, return 5 (Voice file).
- If the first character is
/, return 2 (Translation).
- Else, if the string contains a
.:
- If extension is
gif, return 7 (Animated image).
- If extension is
jpg, return 6 (Image).
- If extension is
html, return 8 (Webpage).
- Else, return
1 (Definition).
Data Extraction (extractData)
- If the line starts with
-, +, *, or /, the data is the substring starting from index 1.
- Otherwise, the data is the entire line.
User Commands (processUserCommands, handleCommand)
Use StringReader to read commands in a loop until "exit" is entered.
Process the following commands:
define w: Get record with Key(label=w, type=1). Print data or "The word w is not in the ordered dictionary".
translate w: Get record with Key(label=w, type=2). Print data or "There is no definition for the word w".
sound w: Get record with Key(label=w, type=3). Play sound or print "There is no sound file for w".
play w: Get record with Key(label=w, type=4). Play music or print "There is no music file for w".
say w: Get record with Key(label=w, type=5). Play voice or print "There is no voice file for w".
show w: Get record with Key(label=w, type=6). Show image or print "There is no image file for w".
animate w: Get record with Key(label=w, type=7). Show image or print "There is no animated image file for w".
browse w: Get record with Key(label=w, type=8). Show webpage or print "There is no webpage called w".
add w t c: Insert Record((w,t),c). If exists, print "A record with the given key (w,t) is already in the ordered dictionary".
delete w k: Remove record with Key(w,k). If missing, print "No record in the ordered dictionary has key (w,k)".
list prefix: Print all labels starting with prefix. If none, print "No label attributes in the ordered dictionary start with prefix [prefix]".
first: Print attributes of the record with the smallest key (label,type,data).
last: Print attributes of the record with the largest key (label,type,data).
exit: Terminate the program.
- Invalid Command: Print "Invalid command".
Multimedia Handling
- Use
SoundPlayer.play(String) for types 3, 4, 5.
- Use
PictureViewer.show(String) for types 6, 7.
- Use
ShowHTML.show(String) for type 8.
- Catch
MultimediaException and handle errors appropriately.
Anti-Patterns
- Do not use
StringReader for reading the input file; use BufferedReader with FileReader.
- Do not invent new commands or error messages not specified in the requirements.
Triggers
- implement the interface class
- process input file
- handle user commands
- determine type
- java dictionary interface
1---2name: java-multimedia-dictionary-interface-implementation3description: Implement a Java Interface class that parses a specific file format into an ordered dictionary and processes user commands to retrieve or manipulate multimedia records based on type and label.4---56# Java Multimedia Dictionary Interface Implementation78Implement a Java Interface class that parses a specific file format into an ordered dictionary and processes user commands to retrieve or manipulate multimedia records based on type and label.910## Prompt1112# Role & Objective13You are a Java developer implementing an `Interface` class for a multimedia ordered dictionary application. The class must read an input file, populate a `BSTDictionary`, and handle user commands to display or play content.1415# Operational Rules & Constraints1617## File Processing (`processInputFile`)181. Read the input file specified in `args[0]`.192. Read the file line by line:20 - Odd lines (1, 3, 5...) are the `label`.21 - Even lines (2, 4, 6...) represent the type and data (`ℓ`).223. For each pair, determine the type and data using the logic below, then insert a `Record` into the `BSTDictionary`.23 - Convert the label to lowercase before creating the `Key`.2425## Type Determination (`determineType`)26Analyze the string `ℓ` to determine the integer type:27- If the first character is `-`, return `3` (Sound file).28- If the first character is `+`, return `4` (Music file).29- If the first character is `*`, return `5` (Voice file).30- If the first character is `/`, return `2` (Translation).31- Else, if the string contains a `.`:32 - If extension is `gif`, return `7` (Animated image).33 - If extension is `jpg`, return `6` (Image).34 - If extension is `html`, return `8` (Webpage).35- Else, return `1` (Definition).3637## Data Extraction (`extractData`)38- If the line starts with `-`, `+`, `*`, or `/`, the data is the substring starting from index 1.39- Otherwise, the data is the entire line.4041## User Commands (`processUserCommands`, `handleCommand`)42Use `StringReader` to read commands in a loop until "exit" is entered.43Process the following commands:4445- `define w`: Get record with Key(label=`w`, type=1). Print data or "The word w is not in the ordered dictionary".46- `translate w`: Get record with Key(label=`w`, type=2). Print data or "There is no definition for the word w".47- `sound w`: Get record with Key(label=`w`, type=3). Play sound or print "There is no sound file for w".48- `play w`: Get record with Key(label=`w`, type=4). Play music or print "There is no music file for w".49- `say w`: Get record with Key(label=`w`, type=5). Play voice or print "There is no voice file for w".50- `show w`: Get record with Key(label=`w`, type=6). Show image or print "There is no image file for w".51- `animate w`: Get record with Key(label=`w`, type=7). Show image or print "There is no animated image file for w".52- `browse w`: Get record with Key(label=`w`, type=8). Show webpage or print "There is no webpage called w".53- `add w t c`: Insert Record((`w`,`t`),`c`). If exists, print "A record with the given key (w,t) is already in the ordered dictionary".54- `delete w k`: Remove record with Key(`w`,`k`). If missing, print "No record in the ordered dictionary has key (w,k)".55- `list prefix`: Print all labels starting with `prefix`. If none, print "No label attributes in the ordered dictionary start with prefix [prefix]".56- `first`: Print attributes of the record with the smallest key (label,type,data).57- `last`: Print attributes of the record with the largest key (label,type,data).58- `exit`: Terminate the program.59- **Invalid Command**: Print "Invalid command".6061## Multimedia Handling62- Use `SoundPlayer.play(String)` for types 3, 4, 5.63- Use `PictureViewer.show(String)` for types 6, 7.64- Use `ShowHTML.show(String)` for type 8.65- Catch `MultimediaException` and handle errors appropriately.6667# Anti-Patterns68- Do not use `StringReader` for reading the input file; use `BufferedReader` with `FileReader`.69- Do not invent new commands or error messages not specified in the requirements.7071## Triggers7273- implement the interface class74- process input file75- handle user commands76- determine type77- java dictionary interface