Return to Jeff's Main Page

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
My Intro to Object-Oriented Programming  
 
 
Programming Challenge Archive

Programming Assignment # 5
OfficialWordTestApp.java
 
In this assignment,  CG provided us with test programs to run classes we refined.    The classes were Word.java and Dictionary.java .    The test programs were OfficialWordTestApp.java and OfficialDictionaryTestApp.java .  

 
  JavaApplication - Programming Assignment # 5  -- OfficialWordTestApp.java

   // General Information
   // ---------------------------------------------------
  
   // File:  WordTestApp.java
   // Type:  java application file
   // Date:  Tue Dec 05, 2000
   // Name:  Jeffrey R. Norkoli
   // 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 OfficialWordTestApp
      {
         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
   // ---------------------------------------------------
  
   /*
   $ javac OfficialWordTestApp.java
   $ java OfficialWordTestApp   
   READ AND DISPLAY 3 WORDS.
   parallel ( par al lel )
   distributed ( dis tri bu ted )
   processing ( pro cess ing )
  
   CREATE AND DISPLAY 2 WORDS.
   mind ( mind )
   design ( de sign )
  
   THE WORD LENGTHS...
   parallel ( par al lel )
   Length = 8
   distributed ( dis tri bu ted )
   Length = 11
   processing ( pro cess ing )
   Length = 10
   mind ( mind )
   Length = 4
   design ( de sign )
   Length = 6
  
   THE SYLLABLE COUNTS...
   parallel ( par al lel )
   nr syllables = 3
   distributed ( dis tri bu ted )
   nr syllables = 4
   processing ( pro cess ing )
   nr syllables = 3
   mind ( mind )
   nr syllables = 1
   design ( de sign )
   nr syllables = 2
  
   DISPLAY THE WORDS ALPHABETICALLY...
   design
   distributed
   mind
   parallel
   processing
  
   DISPLAY REVERSE ALPHABETICALY...
   processing
   parallel
   mind
   distributed
   design
  
   DISPLAY LAST SYLLABLES...
   ing
   lel
   mind
   ted
   sign
   $ 
   */