Problem 9.3

CIS 210 Home Page Last updated 2007/11/04 11:14:37

Problem 9.3: More Phone Codes

If you did Problem 9.1, you translated a phone number containing letters into one with just digits. In this problem, we'll do the reverse. That is, we will generate all of the letter sequences that could produce a given phone number.

In this problem, you are to program a class named PhoneToCode with a method printWords that will print out all of the possible letter combinations that map to the phone number given as a command line argument, using the mapping between letters and digits on a telephone keypad. As a bonus, the method will return a count of the number of combinations printed.

The specific requirements about the listing are:

Here are some examples:

> java PhoneToCode 364
DMG  DMH  DMI
DNG  DNH  DNI
DOG  DOH  DOI
EMG  EMH  EMI
ENG  ENH  ENI
EOG  EOH  EOI
FMG  FMH  FMI
FNG  FNH  FNI
FOG  FOH  FOI
Total combinations: 27

This example has zeroes:
> java PhoneToCode 40-4003
G0-G00D  G0-G00E  G0-G00F
G0-H00D  G0-H00E  G0-H00F
G0-I00D  G0-I00E  G0-I00F
H0-G00D  H0-G00E  H0-G00F
H0-H00D  H0-H00E  H0-H00F
H0-I00D  H0-I00E  H0-I00F
I0-G00D  I0-G00E  I0-G00F
I0-H00D  I0-H00E  I0-H00F
I0-I00D  I0-I00E  I0-I00F
Total combinations: 27


The phone number to be translated is given as a command line argument, or will be prompted for. Start with the code in PhoneToCode.java.

Constraints and Hints

Turn-in

Turn in your PhoneToCode.java.