Developer's Daily Java Education - Test Projects
  front page | java | perl | unix | DevDirectory
   
Front Page
Java
Education
   
 


//import java.util.HashMap;

public class PhoneNumberConverter
{

  private static HashMap characterToNumberMap = new HashMap();

 // public static String splitstring()
  {
   //take the strings into this method and split them into an array
   //of characters
 //  return something;
   }
  /**
   *
   */
  public static int convertCharacterToNumber(char c)
  {
    // 1. initialize the char-to-number map
    initializeCharacterToNumberMap();


    // 2a. convert the character to uppercase
    Character charToLookup = new Character( Character.toUpperCase(c) );

    // 2b. get the number for the given char
    Integer theRightNumber = (Integer)characterToNumberMap.get(charToLookup);

    // 3. return that number
    return theRightNumber.intValue();
  }

  /**
   * Internally this method sets all characters to uppercase
   */
  private static void initializeCharacterToNumberMap()
  {
    characterToNumberMap.put( new Character('A'), new Integer(2) );
    characterToNumberMap.put( new Character('B'), new Integer(2) );
    characterToNumberMap.put( new Character('C'), new Integer(2) );
    characterToNumberMap.put( new Character('D'), new Integer(3) );
    characterToNumberMap.put( new Character('E'), new Integer(3) );
    characterToNumberMap.put( new Character('F'), new Integer(3) );
  }

}
Copyright 1998-2003 DevDaily Interactive, Inc.
All Rights Reserved.