title: Telephone Word generator java program
body: <p>I was trying to write a java program that would convert a telephone number into different combinations of words. </p>
  
  <blockquote>
    <p>Many people find it difficult to memorize phone numbers so they use
    the correspondence between digits and letters to develop seven-letter
    words that correspond to their phone numbers.  For example, a person
    whose telephone number is 686-2377 might use the correspondence
    indicated in Figure Telephone keypad digits and letters to develop the
    seven-letter word “NUMBERS.”  Every seven-letter word corresponds to
    exactly one seven-digit telephone number. Every seven-letter phone
    number corresponds to many different seven-letter words, but most of
    these words represent unrecognizable juxtapositions of letters. Write
    a program that, given a seven-digit number supplied by the user, uses
    a PrintStream object to write to a file every possible seven-letter
    word combination corresponding to that number. There are 2,187 (3^7)
    such combinations.  Avoid phone numbers with the digits 0 and 1.</p>
  </blockquote>
  
  <p>In the program I am having problems with the main method. Is it wrong or I am putting it in the wrong place?</p>
  
  <p>Here is my program:</p>
  
  <pre><code>public class TelephoneNumberWordGenerator
  
  {
  
      String phoneNumber;
      char numberLetters[][] = {
              {'0','0','0'},{'1','1','1'},{'A','B','C'},
              {'D','E','F'},{'G','H','I'},{'J','K','L'},
              {'M','N','O'},{'P','R','S'},
              {'T','U','V'},{'W','X','Y'}};
  
  
      Scanner input = new Scanner (System.in);
      private ObjectOutputStream output;
      PrintStream printStream;
      char[] word = new char [7];
  
  
      public static void main(String[] args){
      public void getPhoneNumber(){
              System.out.println("Enter a seven-digit telephone number: ");
              phoneNumber = input.next();
  
          }
      }
  
      public void openFile()
      {
          try // open file
          {
              output = new ObjectOutputStream(
                      new FileOutputStream ( "Phonenumber.txt") );
  
          }// end try
          catch ( IOException ioEcception )
          {
              System.err.println( "Error opening file.");
          } // end catch
      }// end method open file
  
      public void addFileInfo( )
      {
          try
          {
              char[] chars = phoneNumber.toCharArray ();
              int [] digit = new int [chars.length];
              for (int i = 0; i &lt; chars.length; i++)
              {
                  digit[i] = Integer.parseInt(String.valueOf(chars[i]));
              }
  
              printStream = new PrintStream(output);
              printStream.println("\n");
  
  
              for ( int level0 = 0; level0 &lt; 3; level0 ++ )
              {
                  word[0] = numberLetters[digit[0]][level0];
  
                  for ( int level1 = 0; level1 &lt; 3; level1 ++ )
                  {
                      word[1] = numberLetters[digit[1]][level1];
  
                      for ( int level2 = 0; level2 &lt; 3; level2 ++ )
                      {
                          word[2] = numberLetters[digit[2]][level2];
  
                          for ( int level3 = 0; level3 &lt; 3; level3 ++ )
                          {
                              word[3] = numberLetters[digit[3]][level3];
  
                              for ( int level4 = 0; level4 &lt; 3; level4 ++ )
                              {
                                  word[4] = numberLetters[digit[4]][level4];
  
                                  for ( int level5 = 0; level5 &lt; 3; level5 ++ )
                                  {
                                      word[5] = numberLetters[digit[5]][level5];
  
                                      for ( int level6 = 0; level6 &lt; 3; level6 ++ )
                                      {
                                          word[6] = numberLetters[digit[6]][level6];
                                          printStream.print(word);
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
  
              System.out.println("File written.");
              System.exit(1);
  
          }
          catch (Exception exception )
          {
              System.err.println( "Error writing to file.");
              System.exit(1);
          }
      }
  
      public void closeFile()
      {
          try // close file
          {
              if ( output != null )
                  output.close();
          }// end try
          catch (IOException ioException )
          {
              System.err.println( "Error closing file.");
              System.exit(1);
          }// end catch
  
  
      }// end method closeFile
  }
  </code></pre>