Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an application that takes as input phone number in numeric or alpha form a

ID: 3639796 • Letter: W

Question

Write an application that takes as input phone number in numeric or alpha form and displays the phone number in numeric format. In other words,
If the input is: The output will be:
7601234567 760-123-4567
888IFLYSWA 888-435-9792

The letters and digits are grouped this way:
2=ABC 3=DEF 4=GHI 5=JKL 6=MNO 7=PQRS
8=TUV 9=WXYZ
1. The phone numbers will always be 10 characters long; if the input value is not 10 characters, display
an error message “Invalid Phone Number”.
2. The alpha characters can be either lower case or upper case; both lower case and upper case
alphabets will use the above grouping.
3. We can assume that the input number will only have number or alpha characters

Explanation / Answer

please rate - thanks

import java.util.*;
public class Telephone
{public static void main(String[] args)
{String number;
int i;
System.out.print("Enter phone number: ");
Scanner in = new Scanner(System.in);
number = in.next();
System.out.print(number+" ");
if(number.length()==10)
{
i=0;

while(i<number.length())
    {if(i==3||i==6)
         System.out.print("-");
    switch(Character.toUpperCase(number.charAt(i)))
     {case 'A':case 'B':case 'C':
          System.out.print("2");
          break;
      case 'D':case 'E':case 'F':
          System.out.print("3");
          break;
       case 'G':case 'H':case 'I':
          System.out.print("4");
          break;
        case 'J':case 'K':case 'L':
          System.out.print("5");
          break;
        case 'M':case 'N':case 'O':
          System.out.print("6");
          break;
        case 'P':case 'R':case 'S':
          System.out.print("7");
          break;
        case 'T':case 'U':case 'V':
          System.out.print("8");
          break;
        case 'W':case 'X':case 'Y':
          System.out.print("9");
          break;
        default:
           System.out.print(number.charAt(i));
        }
       i++;
       }
}
else
    System.out.println(" Invalid Phone Number");      
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote