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


import java.util.HashMap;

/**
 * Title:
 * Description:  Convert things like 1-800-GO-FEDEX to their numerical equivalent.
 * Copyright:    Copyright (c) 2001
 * Company:
 * @author
 * @version 1.0
 */

public class PhoneNumberConverter
{

  private static HashMap characterToNumberMap = new HashMap();

  public static String convertStringToNumbers(String s)
  {
    String letters = "gofedex";
    CharArray(letters);
  }


  /**
   *
   */
  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.