import javax.swing.JOptionPane;

    public class TelephoneDigitProgram
   {
   
       public static void main(String[] args)
      {
         char letter;
         String inputMessage, inputString, outputMessage;
         int phoneDigit = 0;
      
         inputMessage = "This program converts 2-9 to uppercase " +
            			"letters corresponding to their" +
            			"telephone digits.\nTo stop the " +
            			"program enter Q or Z.\n" +
            			"Enter a letter:";
         inputString = JOptionPane.showInputDialog(inputMessage);
         
      	// initialize loop control variable
			if (inputString != null && !inputString.equals(""))
			{
					phoneDigit = Integer.parseInt(inputString);
			}
			else
					phoneDigit = 0;
               
         while (phoneDigit >= 2 && phoneDigit <= 9) {
				letter = ' ';
            outputMessage = "The number you entered is: " +
               			 phoneDigit + "\nThe corresponding " +
               			 "telephone letter is ";
         					 
         	// find telephone digit that matches letter
            switch (phoneDigit) {
               case 2:
                  letter = 'A';
                  break;
               case 3:
						letter = 'D';
                  break;
					case 4:
               	letter = 'G';
                  break;
               case 5:
						letter = 'J';
                  break;
               default: 
                  letter = ' ';
            } // end switch
            
            if (letter > ' ') {
               outputMessage += letter;
            }
            else {
            	// input was not valid
               outputMessage += "Invalid input";
            }
         	
         	// display answer to user
            JOptionPane.showMessageDialog (null, outputMessage,
               									 "Telephone Digit", 
               									 JOptionPane.PLAIN_MESSAGE);
         						
            inputMessage = "Enter another uppercase number " +
               				"to be converted to the corresponding " +
               				"telephone letter.\nTo stop the program " +
               				"enter Q or Z.\nEnter a letter:";
         						
            inputString = JOptionPane.showInputDialog(inputMessage);
    
	 			        
				//System.out.println("The line is " + inputString);
         	// update loop control variable
				if (inputString != null && !inputString.equals(""))
				{
            	phoneDigit = Integer.parseInt(inputString);
				}
				else
					phoneDigit = 0;
				
         } // end while
         
         System.exit(0);
      } // end main method
   } // end class TelephoneDigitProgram