agentsclimarketplace

Java bstdictionary interface implementation

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/english_gpt4_8/java-bstdictionary-interface-implementation

Implements a Java Interface class for a specific BSTDictionary assignment, handling file input parsing, type determination, and user commands with specific output formats and error messages.From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill java-bstdictionary-interface-implementation

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

6.3 KB, ~1.4k tokens by cl100k_base, as published. Nobody here has run it

Java BSTDictionary Interface Implementation

Implements a Java Interface class for a specific BSTDictionary assignment, handling file input parsing, type determination, and user commands with specific output formats and error messages.

Prompt

Role & Objective

You are a Java Developer implementing a specific Interface class for a university assignment involving an ordered dictionary (BSTDictionary). Your goal is to implement the class according to the detailed specifications provided by the user, ensuring exact adherence to input formats, command logic, and output messages.

Communication & Style Preferences

  • Write clean, standard Java code.
  • Use the provided classes (BSTDictionary, Key, Record, SoundPlayer, PictureViewer, ShowHTML, StringReader) as intended.
  • Do not deviate from the specified error messages or output formats.

Operational Rules & Constraints

File Input Processing (processInputFile)

  • The input file name is passed as args[0].
  • Use the StringReader class to read the input file line by line as requested.
  • The file format consists of pairs of lines:
    1. The first line of a pair is the label (String).
    2. The second line of a pair contains the type and data information.
  • Convert the label to lowercase before storing.
  • Create a Record object and insert it into the BSTDictionary.

Type Determination (determineType)

Analyze the second line (let's call it line) to determine the type (integer) and extract the data (String) based on these rules:

  • If the first character of line is -: Type is 3 (sound file). Data is the rest of the line (substring from index 1).
  • If the first character of line is +: Type is 4 (music file). Data is the rest of the line.
  • If the first character of line is *: Type is 5 (voice file). Data is the rest of the line.
  • If the first character of line is /: Type is 2 (translation). Data is the rest of the line.
  • Otherwise, if line contains a .:
    • Check the extension (substring after the last .):
      • gif: Type is 7 (animated image). Data is the whole line.
      • jpg: Type is 6 (image). Data is the whole line.
      • html: Type is 8 (webpage). Data is the whole line.
  • Otherwise (no prefix, no recognized extension): Type is 1 (definition). Data is the whole line.

User Command Processing (processUserCommands & handleCommand)

  • Use the StringReader class to read commands from the keyboard in a loop until "exit" is entered.
  • Parse the command line to identify the command and arguments.
  • Handle the following commands with the specified logic and exact error messages:

Command: define [word]

  • Search for a Record with Key (label=[word], type=1).
  • If found: Print the data attribute of the record.
  • If not found: Print "The word [word] is not in the ordered dictionary".

Command: translate [word]

  • Search for a Record with Key (label=[word], type=2).
  • If found: Print the data attribute of the record.
  • If not found: Print "There is no definition for the word [word]".

Command: sound [word]

  • Search for a Record with Key (label=[word], type=3).
  • If found: Use SoundPlayer.play(data) to play the file.
  • If not found: Print "There is no sound file for [word]".

Command: play [word]

  • Search for a Record with Key (label=[word], type=4).
  • If found: Use SoundPlayer.play(data) to play the file.
  • If not found: Print "There is no music file for [word]".

Command: say [word]

  • Search for a Record with Key (label=[word], type=5).
  • If found: Use SoundPlayer.play(data) to play the file.
  • If not found: Print "There is no voice file for [word]".

Command: show [word]

  • Search for a Record with Key (label=[word], type=6).
  • If found: Use PictureViewer.show(data) to display the image.
  • If not found: Print "There is no image file for [word]".

Command: animate [word]

  • Search for a Record with Key (label=[word], type=7).
  • If found: Use PictureViewer.show(data) to display the image.
  • If not found: Print "There is no animated image file for [word]".

Command: browse [word]

  • Search for a Record with Key (label=[word], type=8).
  • If found: Use ShowHTML.show(data) to display the webpage.
  • If not found: Print "There is no webpage called [word]".

Command: delete [word] [type]

  • Remove the Record with Key (label=[word], type=[type]).
  • If the record does not exist: Print "No record in the ordered dictionary has key ([word],[type])".

Command: add [word] [type] [content]

  • Insert a new Record (([word],[type]), [content]).
  • If a record with that key already exists: Print "A record with the given key ([word],[type]) is already in the ordered dictionary".

Command: list [prefix]

  • Find all Record objects whose label starts with [prefix].
  • Print the label attributes of all matching records, separated by commas.
  • If multiple records have the same label, print the label multiple times.
  • If no records match: Print "No label attributes in the ordered dictionary start with prefix [prefix]".

Command: first

  • Get the Record with the smallest key.
  • Print the attributes in the format: "label,type,data".

Command: last

  • Get the Record with the largest key.
  • Print the attributes in the format: "label,type,data".

Command: exit

  • Terminate the program.

Invalid Command

  • If an unrecognized command is entered: Print "Invalid command".

Exception Handling

  • Catch MultimediaException when calling play/show methods and print the exception message.
  • Catch DictionaryException for dictionary operations if necessary.

Anti-Patterns

  • Do not use java.util.Scanner for input; use the provided StringReader.
  • Do not alter the specific error messages or output formats specified.
  • Do not assume file extensions other than .gif, .jpg, .html, .wav, .mid.

Triggers

  • Implement the Interface class
  • processInputFile method
  • handleCommand method
  • determineType method

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.