Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Companies often like to create word equivalents for their phone numbers, so customers can remember them more easily. For example, 4 3 8 - 4
Companies often like to create word equivalents for their phone numbers, so customers can remember them more easily.
For example, could translate to GETHELP on a phone keypad.
This program will help a company determine what letters could be used with their phone numbers.
Start with the supplied code template, editing the top of program comment to include your FULL NAME.
Note that two constants have been declared within the template:
final int PHONESTRINGLENGTH ;
final int DASHINDEX ;
You must use these constants in your code.
Extend the template code to read a digit phone number with a dash from the user, and display the String that was read.
Then use a String method to search the String and determine the which digits it contains
For each digit found, print a list of its possible letter values.
NOTE: You can search for each digit as a String or as a character, but NOT as an integer number eg or but not
Support the following digits, searching for them in the order listed:
ABC
DEF
GHI
JKL
MNO
PQRS
TUV
WXYZ
Sample interleaved inputoutput:
Enter phone number #######:
You entered:
Letters options for are DEF
Letters options for are MNO
Further extend the code to add error checking.
When a phone number contains the digit or the digit then it cannot be translated to word equivalents,
because there are no letters that match or
Search for and before searching for digits through
When either or is found, display the error message shown below,
and do not translate any other digits.
Sample interleaved inputoutput:
Enter phone number #######:
You entered:
There are no letter options for or
Further extend the code to add more error checking.
Use String methods and the constants defined in the template to determine
whether the phone number entered was either too short or too long.
And when it is the correct length, determine whether there is not a dash in the correct location.
When necessary, display one of the error messages shown below, instead of any other output
ie don't check the digits unless the length and dash are correct
NOTE: Use efficient decision making code.
Sample interleaved inputoutput:
Enter phone number #######:
Invalid phone number: too short
Enter phone number #######:
Invalid phone number: too long
Enter phone number #######:
Invalid phone number: dash missing or in wrong place
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started