Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 10 Weeks Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Write a program that takes an input from the keyboard representing a telephone number. The input will be valid if it contains 10 digits that are optionaly separated by either space or hyphen after the first and the second block of three digits. For example all the following should be considered valid phone numbers:
Â
Validate the input with matches method and using a do-while loop keep prompting the user until the valid input is given.
Once you have a valid telephone number, you should assume that the digits (only the digits, not hyphen or space) may have been encrypted by shifting each number by a constant value. For instance, if the shift is 2, 0 becomes 2, 1 becomes 3, 2 becomes 4, ..., 8 becomes 0, and 9 becomes 1.
We know that the user is from New York where the decrypted area code (after the shift is applied), represented by the first three digits of the input, is 212.
Your program needs to decrypt the telephone number and output the decrypted telephone number, as well as the shift value of the encyption. If there area code cannot be decrypted to 212, you should output that information instead.