title: Alphabetizing words in java
body: <p>Here is my program and I am not sure what is wrong with it. If I delete the Alphabetizing method it works totally fine, can someone tell me what is wrong with this method and how to fix it. The first part I am supposed to print the words as they appear, the second part I am supposed to Capitalize them, then the third part I am supposed to add a hyphen and remove the space between the words and finally the last part I am supposed to alphabetize them.</p>
  
  <pre><code>import static java.lang.System.*;
  
  public class WordFun {
  
      private String word, loc, changedWord;
  
      public WordFun() {
      }
  
      public WordFun(String w) {
          word = w;
          changedWord = w;
      }
  
      public void setWord(String w) {
      }
  
      public void makeUpper() {
          changedWord = word.toUpperCase();
      }
  
      public void addHyphen() {
          String hyphen = word.trim();
          changedWord = word.replaceAll(" ", "-");
      }
  
      public void alphabetize() {
          int loc;
          loc = original.indexOf(" ");
          String wordOne = original.substring(0, loc);
          String wordTwo = original.substring(loc + 1, word.length());
          if (wordOne.compareTo(wordTwo) &gt; 0) {
              word = wordTwo + " " + wordOne;
          } else {
              word = wordOne + " " + wordTwo;
          }
      }
  
      public String toString() {
          return changedWord;
      }
  }
  </code></pre>
  
  <p>Here is the runner program</p>
  
  <pre><code>import static java.lang.System.*;
  
  public class WordFunRunner {
  
      public static void main(String args[]) {
          WordFun test = new WordFun("Hello World");
          out.println(test);
          test.makeUpper();
          out.println(test);
          test.addHyphen();
          out.println(test);
          test.alphabetize();
          out.println(test);
  
  //add more test cases
          WordFun test1 = new WordFun("Jeroo Bob");
          out.println(test1);
          test1.makeUpper();
          out.println(test1);
          test1.addHyphen();
          out.println(test1);
          test1.alphabetize();
          out.println(test1);
  
          WordFun test2 = new WordFun("Computer Science");
          out.println(test2);
          test2.makeUpper();
          out.println(test2);
          test2.addHyphen();
          out.println(test2);
          test2.alphabetize();
          out.println(test2);
  
          WordFun test3 = new WordFun("Golden Bears");
          out.println(test3);
          test3.makeUpper();
          out.println(test3);
          test3.addHyphen();
          out.println(test3);
          test3.alphabetize();
          out.println(test3);
  
          WordFun test4 = new WordFun("Upper Arlington");
          out.println(test4);
          test4.makeUpper();
          out.println(test4);
          test4.addHyphen();
          out.println(test4);
          test4.alphabetize();
          out.println(test4);
      }
  }
  </code></pre>