//Use a Map to make a dictionary
import java.util.*;
import java.io.*;
class Words
{
static final int verb = 0;
static final int noun = 1;
static final int adjective = 2;
static final int adverb = 3;
int Index;
String Description;
public Words (int Number, String Definition)
{
Index = Number;
Description = Definition ;
}
public String toString () {
switch (Index) {
case verb : return " [verb] : " + Description;
case noun : return " [noun] : " + Description;
case adjective : return " [adjective] : " + Description;
case adverb : return " [adverb] : " + Description;
default : return " ";
}
}
}
public class TheDictionary
{
public static void ReSearch(String TheWord)
{
TreeMap map = new TreeMap ();
// Insert words:
// ---------------
// 1. Nouns:
map.put("acceleration", new Words(Words.noun," the change in the velocity"));
map.put("velocity", new Words(Words.noun," the change in the displacement"));
map.put("displacement", new Words(Words.noun," the change in the position"));
// 1. Verbs:
map.put("move", new Words(Words.verb," to change the place"));
map.put("weight", new Words(Words.verb," to have a mass through an acceleration"));
map.put("rotate", new Words(Words.verb," to revolve, to turn around"));
// 1. Adjectives:
map.put("heavy", new Words(Words.adjective,"difficult to lift"));
map.put("slowly", new Words(Words.adjective,"moving with a low speed"));
map.put("inert", new Words(Words.adjective,"static, not moving"));
// 1. Adverbs:
map.put("franckly", new Words(Words.adverb,"truthfully"));
map.put("logically", new Words(Words.adverb,"reasonably"));
map.put("energitically", new Words(Words.adverb,"actively"));
//Serach of words:
//----------------------
System.out.println("\n");
System.out.println("\tHere are the results from The Dictionary\n");
System.out.println("\t----------------------------------------\n");
if (map.containsKey(TheWord))
System.out.println("\t " + TheWord + map.get(TheWord)+"\n");
else
System.out.println("\t The word: " + TheWord + " is not in this dictionary.\n");
// Display the first word and the last one.
System.out.println();
System.out.println("\t First word in this dictionary: " + map.firstKey()+"\n");
System.out.println("\t Last word in this dictionary: " + map.lastKey()+"\n");
}
public static void main (String[] args) throws IOException
{
// TreeMap map = new TreeMap ();
BufferedReader entrance = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\n\t Enter a word: --> ");
String TheWord = entrance.readLine();
ReSearch(TheWord); // ReSearch(map, TheWord);
}
}
|