



|
|
Byron's CSC212 Web Site
|
Programming Challenge Archive
Word Dictionary
Dictionary Test App
|
|
|
JavaApplication --
OfficialDictionaryTestApp
// General Information
// ---------------------------------------------------
// File: DictionaryTestApp.java
// Type: java application file
// Date: Wed Nov 15, 2000
// Name: blue
// Line: Test program for the Dictionary class
// Application Description
// ---------------------------------------------------
/*
Official test program for the Dictionary class
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import white.words.*;
// Application Class
// ---------------------------------------------------
class DictionaryTestApp
{
static public void main (String args[])
{
// Create a little dictionary and display it.
// Internally create and display two words.
IO.println();
IO.println("--> INTERNALLY CREATE 2 WORDS.");
String as[] = new String[1];
as[0] = "mind";
Word a = new Word("mind",as);
String bs[] = new String[2];
bs[0] = "de";
bs[1] = "sign";
Word b = new Word("design",bs);
a.display();
b.display();
// Internally create and display a dictionary
IO.println();
IO.println("--> INTERNALLY CREATE DICTIONARY.");
Dictionary small = new Dictionary("Small");
small.add(a);
small.add(b);
small.display();
// Create and display a second dictionary, from exte+
rnal
// sources
IO.println();
IO.print("--> CREATE A DICTIONARY EXTERNALLY");
Dictionary pldehp = new Dictionary("pldehp");
pldehp.add("wf1.data");
pldehp.add("wf2.data");
pldehp.add("wf3.data");
pldehp.display();
// Search for languages
IO.println();
IO.println("SEARCHING FOR LANGUAGES...");
String[] claysyllables = new String[1];
as[0] = "clay";
Word clay = new Word("clay",as);
String smalltalksyllables[] = new String[2];
smalltalksyllables[0] = "small";
smalltalksyllables[1] = "talk";
Word smalltalk = new Word("smalltalk",smalltalksy+
llables);
if ( pldehp.search(clay) )
{
IO.println("CLAY is in the dictionary.");
}
else
{
IO.println("CLAY is NOT in the dictionary.");+
}
if ( pldehp.search(smalltalk) )
{
IO.println("SMALLTALK is in the dictionary.")+
;
}
else
{
IO.println("SMALLTALK is NOT in the dictionar+
y.");
}
int xclay = pldehp.search("clay");
IO.println("Position of CLAY = " + xclay);
int xsmalltalk = pldehp.search("smalltalk");
IO.println("Position of SMALLTALK = " + xsmalltal+
k);
// Sort the dictionary alphabetically
IO.println();
IO.println("DICTIONARY IN ALPHABETICAL ORDER.");
pldehp.sort();
pldehp.display();
// Sort the dictionary by length
IO.println();
IO.println("DICTIONARY ORDERED BY WORD LENGTH.");+
pldehp.sortByLength();
pldehp.display();
// Sort the dictionary by syllable count
IO.println();
IO.println("DICTIONARY ORDERED BY SYLLABLE COUNT.+
");
pldehp.sortBySyllableCount();
pldehp.display();
// Select 10 words at random from PLDEHP
IO.println();
IO.println("--> PRINT 10 RANDOM WORDS FROM PLDEHP+
.");
for ( int x = 1; x <= 10; x++ )
{
pldehp.select().println();
}
// Select 10 2-syllable words at random from PLDEHP
IO.println();
IO.println("--> PRINT 10 RANDOM 2 SYLLABLE WORDS.+
");
for ( int x = 1; x <= 10; x++ )
{
pldehp.select(2).println();
}
// Select 10 words at random from PLDEHP which
// have "va" "la"
IO.println();
IO.println("--> PRINT 10 RANDOM 'VA LA' WORDS.");+
String[] sounds1 = {"va","la"};
for ( int x = 1; x <= 10; x++ )
{
pldehp.select(sounds1).println();
}
// Select 10 words at random from PLDEHP which
// have "in" "van" "thon"
IO.println();
IO.println("--> PRINT 10 RANDOM 'IN VAN THON' WOR+
DS.");
String[] sounds2 = {"van","in","thon"};
for ( int x = 1; x <= 10; x++ )
{
pldehp.select(sounds2).println();
}
// Select 10 words at random from PLDEHP which
// have 3 syllables and end in either "in" "van" "th+
on"
IO.println();
IO.print("--> PRINT 10 RANDOM ");
IO.print("'IN VAN THON' WORDS ");
IO.println("OF 3 SYLLABLES.");
for ( int x = 1; x <= 10; x++ )
{
pldehp.select(3,sounds2).println();
}
}
}
// Demo
// ---------------------------------------------------
/*
<?DEMO>
*/
|
|
|