AP Computer Science --- Haas --- FourWordList



/*************************************************************************
 * Complete the code below which determines which of 4 strings
 * is first, second, third and fourth in Alphabetical order.  
 * 
 * You will need to use the compareTo method.
 * 
 * You can write additional methods if you need to use them.
 *************************************************************************/
public class FourWordList
{
   private String str1, str2, str3, str4;
   
   public FourWordList(String s1, String s2, String s3, String s4)
   {
      str1 = s1;
      str2 = s2;
      str3 = s3;
      str4 = s4;
   }
   
  /************************************************
   * method that prints the list of four words
   ************************************************/
   public void printWords()
   {
     System.out.println(str1 + ",  " +  str2 + ",  " + str3 + ",  " + str4);
   }
   
   /*******************************************************
    * returns a string which is first in Alphabetical order
    ********************************************************/
   public String getFirst()
   {
       
     //>>>>>>>>>>>>>>>>>>>>> COMPLETE THE CODE <<<<<<<<<<<<<<<<<<<<<<<<  
      
   }
   
   
  /*******************************************************
   * returns a string which is second in Alphabetical order
   ********************************************************/
   public String getSecond()
   {

     //>>>>>>>>>>>>>>>>>>>>> COMPLETE THE CODE <<<<<<<<<<<<<<<<<<<<<<<<  

   }
   
   
  /********************************************************
   * returns a string which is third in Alphabetical order
   ********************************************************/
   public String getThird()
   {
       
      //>>>>>>>>>>>>>>>>>>>>> COMPLETE THE CODE <<<<<<<<<<<<<<<<<<<<<<<<  
  
   }
   
   
   /********************************************************
   * returns a string which is last in Alphabetical order
   *********************************************************/
   public String getLast()
   {
       
     //>>>>>>>>>>>>>>>>>>>>> COMPLETE THE CODE <<<<<<<<<<<<<<<<<<<<<<<<  
 
   }
   
}





/***************************************************
 *  This is a tester class for FourWordList
 *  It IS complete, and should work as is!
 ****************************************************/
public class FourWordListTester
{
   public static void main(String[] args)
   {
      FourWordList w1 = new FourWordList("pizza", "pasta", "cookies", "ice cream");
      w1.printWords();
      System.out.println("in order..." + w1.getFirst() + "," + 
          w1.getSecond()+ "," + w1.getThird()+ "," + w1.getLast());
          
      System.out.println("");
      FourWordList w2 = new FourWordList("ape", "boar", "cat", "dog");
      w2.printWords();
      System.out.println("in order..." + w2.getFirst() + "," + 
          w2.getSecond()+ "," + w2.getThird()+ "," + w2.getLast());
          
      System.out.println("");
      FourWordList w3 = new FourWordList("z", "x", "w", "y");
      w3.printWords();
      System.out.println("in order..." + w3.getFirst() + "," + 
          w3.getSecond()+ "," + w3.getThird()+ "," + w3.getLast());
          
      System.out.println("");
      FourWordList w4 = new FourWordList("Tom", "Sue", "Ron", "Quincy");
      w4.printWords();
      System.out.println("in order..." + w4.getFirst() + "," + 
          w4.getSecond()+ "," + w4.getThird()+ "," + w4.getLast());
  
   }
}