Byron's CSC212 Web Site

CS1 at Oswego

Hypertexknowlogy

Frequently Asked Questions

 
Byron's CSC212 Web Site  
 
 
Programming Challenge Archive

Word Dictionary
Word App
 
 

 
  JavaApplication  -- Word App

   // File header
   // ---------------------------------------------------
  
   // File:  Word.java
   // Type:  java library file
   // Date:  Tue Nov 14, 2000
   // Name:  blue
   // Line:  Model of a "word"
  
   // Library class description
   // ---------------------------------------------------
  
   /*
      A "word" will be modeled in terms of the word
      itself and its syllables.
   */
  
   // Package Identification
   // ---------------------------------------------------
  
      package white.words;
  
  
   // Required Packages
   // ---------------------------------------------------
  
      import blue.io.*;
  
   // Library class
   // ---------------------------------------------------
  
      public class Word
      {
      // instance variables
         private String word;
         private String[] syllables;
         
      // constructors
         public Word()
         {
            word = IO.readString();
            syllables = new String[IO.read_int()];
            for ( int i = 0; i < syllables.length; i++ )
            {
               syllables[i] = IO.readString();
            }
         }
  
         public Word(String s, String[] a)
         {
            word = s;
            syllables = a;
         }
  
  
      // static methods
         public static boolean less(Word x, Word y)
         {
             return ( x.word().compareTo(y.word()) < 0 );
         }
          
          //       public static boolean equals(Word x, Word +
   y)
          //       {
          //       return ( x.word().compareTo(y.word()) = 0 +
   );
          //       }
          
          //       public static boolean greater(Word x, Word+
    y)
          //       {
          //    return ( x.word().compareTo(y.word()) > 0 );
          //       }
          
  
      // instance methods
         public String word()
         {
            return word;
         }
  
         public String[] syllables()
         {
            return syllables;
         }
  
          public String lastSyllable()
         {
            return syllables[syllables.length-1];
         }
  
  
         public void display()
         {
            IO.print(word);
            IO.print(" (");
            for ( int i = 0; i < syllables.length; i++ )
            {
                IO.print(" ");
                IO.print(syllables[i]);
            }
            IO.print(" )");
            IO.println();
         }
  
         public int length()
         {
            return word.length();
         }
  
         public int nrSyllables()
         {
            return syllables.length;
         }
  
  
         public void println()
         {
            IO.println(word);
         }
  
  
      }