



|
|
Byron's CSC212 Web Site
|
Programming Challenge Archive
Program Potpouri ( Lab Programming )
Librarying a Class
|
|
|
This program from Lab # 10 is designed to demonstrate the mechanics of establishing a Library Class which features deliberate program testing.
JavaApplication --
Word Test App
// General Information
// ---------------------------------------------------
// File: WordTestApp.java
// Type: java application file
// Date: Mon Dec 11, 2000
// Name: Byron Bahr
// Line: Test program for the Word class
// Application Description
// ---------------------------------------------------
/*
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();
//Word d = new Word();
//d.display();
IO.println();
// Internally create and display three words.
IO.print("Internally create and display ")
IO.println("3 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);
String cs[] = new String[3];
cs[0] = "con";
cs[1] = "tem";
cs[2] = "plate";
Word c = new Word("contemplate",cs);
a.display();
b.display();
c.display();
IO.println();
// Compute the length of each word
IO.println("The word lengths.");
IO.println("Length of x = " + x.length());
IO.println("Length of y = " + y.length());
IO.println("Length of z = " + z.length());
IO.println("Length of a = " + a.length());
IO.println("Length of b = " + b.length());
IO.println("Length of c = " + c.length());
IO.println();
// Compute the syllable count for each ord
IO.println("The syllable counts.");
IO.println("x has "+x.nrSyllables()+" syllables");
IO.println("y has "+y.nrSyllables()+" syllables");
IO.println("z has "+z.nrSyllables()+" syllables");
IO.println("a has "+a.nrSyllables()+" syllables");
IO.println("b has "+b.nrSyllables()+" syllables");
IO.println("c has "+c.nrSyllables()+" syllables");
IO.println();
// Display the words in alphabetical order
IO.print("Display the words in alphabetical ")
IO.println("order.");
Word words[] = new Word[5];
words[0] = x;
words[1] = y;
words[2] = z;
words[3] = a;
words[4] = b;
words[5] = c;
order(words);
for ( int i = 0; i < words.length; i++ )
{
words[i].println();
}
IO.println();
// Display the last syllable of each word
IO.print("Display the last syllable of each ")
IO.println("word.");
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;
}
}
}
}
}
// Demo
// ------------------------------------------------------
//3456789112345678921234567893123456789412345678951234567
/*
$ javac WordTestApp.java
$ java WordTestApp <WordTestApp.data
Read and display 3 words.
parallel ( par al lel )
distributed ( dis tri bu ted )
processing ( pro cess ing )
Internally create and display 2 words.
mind ( mind )
design ( de sign )
The word lengths.
Length of x = 8
Length of y = 11
Length of z = 10
Length of a = 4
Length of b = 6
The syllable counts.
x has 3 syllables
y has 4 syllables
z has 3 syllables
a has 1 syllables
b has 2 syllables
Display the words in alphabetical order.
design
distributed
mind
parallel
processing
Display the last syllable of each word.
sign
ted
mind
lel
ing
*/
|
|
|