Question
Now that we all live in the 305 area code, we can use theletters on a phone's keyboard to encode our phone numbersas strings, e.g.,
Now that we all live in the 305 area code, we can use theletters on a phone's keyboard to encode our phone numbersas strings, e.g., my office number 3052842158 can be encoded as thestring "E0KAUHA1JV" (note the zero and one are left as 0 and 1). Itcould also be encoded as "F0LAVIC1KU", or "D0JCUHB1LU", or"E0LCUGB1JU", or ... there are lots of random options. You mustwrite a program to make a random string code for a 305phone number that is entered as the last seven digits of thenumber.
Your program must:
Use a do-while loop to make sure the user enters a 7digit number.
Have a method that accepts an integer parameter (the number) andreturns a String that is a random encoding of the number accordingto the normal phone keyboard.
The method must use have two arrays. The first array containsthe first letters for encoding each digit, i.e., '0', '1', 'A','D', ... 'W'. The second array contains the number of letters foreach digit, i.e., 1, 1, 3, 3, ... 4.
The method must use a while loop to extract each digit of thenumber (hint, use the modulus operator), encode the digit randomlyas one of those corresponding to the digit as specified by thearrays (hint, use Math.random and Math.floor), andbuild the encoded string (hint, use the concatenationoperator).
Call the encoding method twice, once to encode 305, and once toencode the seven digit number.
Print out the encoded number.
Here what a sample run should look like (with the keyboard inputshown in italics) ...
Please enter your 305 phone number: 2842158The phone number 3052842158 can be encoded as E0KAUHA1JV
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