Introduction
The international standard letter/number mapping found on the telephone is as follows:
1
2
ABC
3
DEF
4
GHI
5
JKL
6
MNO
7
PQRS
8
TUV
9
WXYZ
0
Write a method that returns a number, given an uppercase letter using the method definition:
public static int getNumber(char upperCaseLetter)
Input
phoneNumberStr -
String
Output
phoneNumber translated to numbers - String
Sample Output:
Enter the phone number string
1-800-flowers
Phone: 1-800-3569377
Enter the phone number string
1800FLOWERS
Phone: 18003569377
Directions
1. Before each significant step, provide a comment explaining the step (do not comment
every line of code).
2. The input is a String. It is recommended you immediately convert this String to
uppercase since 1-800-flowers and 1-800-FLOWERS would both display 1-800-
3569377 as the phone number.
3. You MUST use a for-loop to step through phoneNumberStr.
4.Within the for-loop body, convert only the letters to their equivalent number using the
following algorithm:
a. If the current character of phoneNumberStr is an uppercase letter, call the
method getNumber to determine the number and append (or concatenate) to
phoneNumber. Note that to check if the character is a letter consider the
ASCII range of uppercase letters.
For example, if(phoneNumberStr.charAt(i) == 65) is true when the character
at index i is A.
Also, recall that when considering characters use single quotes – ‘A’
b. If the current character of phoneNumberStr is NOT a letter, you will need to
create a one-character substring and then append/concatenate this substring to
phoneNumber
c. Output the phoneNumber
EXTRA CREDIT (2 points) Include appropriate hypens to the actual phone number.
That is, 1-800-flowers or 1800FLOWERS would display the phone number as
1-800-356-9377