



|
|
Byron's CSC212 Web Site
|
Programming Challenge Archive
Word Dictionary
Word Test App
|
|
|
JavaApplication --
OfficialWordTestApp
// General Information
// ---------------------------------------------------
// File: WordTestApp.java
// Type: java application file
// Date: Wed Nov 15, 2000
// Name: blue
// Line: Test program for the Word class
// Application Description
// ---------------------------------------------------
/*
Official test program for the Word class
*/
// Required Packages
// ---------------------------------------------------
import blue.io.*;
import white.words.*;
// Application Class
// ---------------------------------------------------
class WordTestApp
{
static public void main (String args[])
{
// Read and display three words
IO.println();
IO.println("READ AND DISPLAY 3 WORDS.");
Word x = new Word();
x.display();
Word y = new Word();
y.display();
Word z = new Word();
z.display();
// Internally create and display three words.
IO.println();
IO.println("CREATE AND DISPLAY 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();
// Compute the length of each word
IO.println();
IO.println("THE WORD LENGTHS...");
x.display();
IO.println("Length = " + x.length());
y.display();
IO.println("Length = " + y.length());
z.display();
IO.println("Length = " + z.length());
a.display();
IO.println("Length = " + a.length());
b.display();
IO.println("Length = " + b.length());
// Compute the syllable count for each word
IO.println();
IO.println("THE SYLLABLE COUNTS...");
x.display();
IO.println("nr syllables = " + x.nrSyllables());
y.display();
IO.println("nr syllables = " + y.nrSyllables());
z.display();
IO.println("nr syllables = " + z.nrSyllables());
a.display();
IO.println("nr syllables = " + a.nrSyllables());
b.display();
IO.println("nr syllables = " + b.nrSyllables());
// Display the words in alphabetical order
IO.println();
IO.println("DISPLAY THE WORDS ALPHABETICALLY...")+
;
Word words[] = new Word[5];
words[0] = x;
words[1] = y;
words[2] = z;
words[3] = a;
words[4] = b;
order(words);
for ( int i = 0; i < words.length; i++ )
{
words[i].println();
}
// Display the words in alphabetical order
IO.println();
IO.println("DISPLAY REVERSE ALPHABETICALY...");
revOrder(words);
for ( int i = 0; i < words.length; i++ )
{
words[i].println();
}
// Display the last syllable of each word
IO.println();
IO.println("DISPLAY LAST SYLLABLES...");
for ( int i = 0; i < words.length; i++ )
{
IO.println(words[i].lastSyllable());
}
}
static private void order(Word w[])
{
for ( int i = 0; i < w.length; i++ )
{
for ( int j = i+1; j < w.length; j++ )
{
if ( Word.less(w[j],w[i]) )
{
Word t = w[j];
w[j] = w[i];
w[i] = t;
}
}
}
}
static private void revOrder(Word w[])
{
for ( int i = 0; i < w.length; i++ )
{
for ( int j = i+1; j < w.length; j++ )
{
if ( Word.greater(w[j],w[i]) )
{
Word t = w[j];
w[j] = w[i];
w[i] = t;
}
}
}
}
}
// Demo
// ---------------------------------------------------
/*
<?DEMO>
*/
|
|
|