Answered step by step
Verified Expert Solution
Link Copied!

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, 438-4357 could translate to GET-HELP 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 PHONE_STRING_LENGTH =8;
final int DASH_INDEX =3;
You must use these constants in your code.
(1)
Extend the template code to read a 7-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 (e.g."5" or '5', but not 5)
Support the following digits, searching for them in the order listed:
2- ABC
3- DEF
4- GHI
5- JKL
6- MNO
7- PQRS
8- TUV
9- WXYZ
Sample interleaved input/output:
Enter phone number (###-####):
633-3366
You entered: 633-3366
Letters options for 3 are DEF
Letters options for 6 are MNO
(2)
Further extend the code to add error checking.
When a phone number contains the digit 0 or the digit 1, then it cannot be translated to word equivalents,
because there are no letters that match 0 or 1.
Search for 0 and 1 before searching for digits 2 through 9.
When either 0 or 1 is found, display the error message shown below,
and do not translate any other digits.
Sample interleaved input/output:
Enter phone number (###-####):
773-3220
You entered: 773-3220
There are no letter options for 0 or 1
(3)
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
(i.e. don't check the digits unless the length and dash are correct).
NOTE: Use efficient decision making code.
Sample interleaved input/output:
Enter phone number (###-####):
222
Invalid phone number: too short
Enter phone number (###-####):
222-3333333
Invalid phone number: too long
Enter phone number (###-####):
222344-4
Invalid phone number: dash missing or in wrong place

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago