CS1 Course Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
CS1 Course Site  
 
 
Programming Challenge Archive

Program Potpouri
Librarying a Class
 
This program was featured in the lab devoted to our experiences with the mechanics of establishing a ``library class,  '' adding some functionality to a library class,  to develope a library class which features deliberate program testing,  and to get us started with our final programming assignment.
 
  JavaApplication  -- Word Test App

   // 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
   // ---------------------------------------------------
  
   /*
      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("Read and display 3 words.");
            Word x = new Word();
            x.display();
            Word y = new Word();
            y.display();
            Word z = new Word();
            z.display();
            IO.println();
  
         // Internally create and display three words.
            IO.println("Internally 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();
            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();
  
         // Compute the syllable count for each word
            IO.println("The syllable counts.");
            IO.println("x has " + x.nrSyllables() + " syllabl+
   es");
            IO.println("y has " + y.nrSyllables() + " syllabl+
   es");
            IO.println("z has " + z.nrSyllables() + " syllabl+
   es");
            IO.println("a has " + a.nrSyllables() + " syllabl+
   es");
            IO.println("b has " + b.nrSyllables() + " syllabl+
   es");
            IO.println();
  
         // Display the words in alphabetical order
            IO.println("Display the words in alphabetical ord+
   er.");
            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 last syllable of each word
            IO.println("Display the last syllable of each wor+
   d.");
            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
   // ---------------------------------------------------
  
   /*
      <?DEMO>
   */