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

Telephone numbers can include one or more alphabetic characters, such as “A”, “c

ID: 3718018 • Letter: T

Question

Telephone numbers can include one or more alphabetic characters, such as “A”, “c”. Write a program that will transform a 10-digit telephone number (may contain one or more alphabetic characters, may contain numeric characters). The user is supposed to enter the 10-digit telephone number one by one digit (loop). Display the telephone number using numerals only and in format “(***)-***-****”. Please consider that both upper case and lower case could be entered.

The numbers and letters are associated as follows on your telephone:

ABC: 2

DEF: 3

GHI: 4

JKL: 5

MNO: 6

PQRS: 7

TUV: 8

WXYZ: 9

Implement the following steps:

(in JAVA)

Prompt user to enter digits of telephone number (may contain one or more alphabetic characters, may contain numeric characters) (loop).

Convert each alphabetic character to associated numbers (if/else or switch case).

Allow both upper case and lower case to be entered.

Display the telephone number using numerals only and in right format.

Explanation / Answer

Note : please run it in any ide or complier.....please find the code as per your requirement...
////////////////PhoneNumber.java///////////////
import java.util.Scanner;
public class PhoneNumber {
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String ch;
int[] arr = new int[10];
System.out.println("Please Enter the 10-digit Telephonic Number Line by Line:");
for(int i=0;i<10;i++){
ch = scanner.next();
char ch1=ch.charAt(0);
int numericValue = Character.getNumericValue(ch.charAt(0));
if(ch1=='s'||ch1=='S'||ch1=='v'||ch1=='V'||ch1=='y'||ch1=='Y'||ch1=='z'||ch1=='Z')
{
numericValue=numericValue-1;
if(ch1=='z'||ch1=='Z'){
numericValue=numericValue-1;
}
}
arr[i]=numericValue;
}
for(int i=0;i<10;i++){
if(arr[i]>=10){
int num = arr[i];
num=num-9;
if(num%3==0){
num=num/3+1;
}
else{
num=num/3+2;
}
arr[i]=num;
}
}
System.out.println("You Number is :");
System.out.print("("+arr[0]+""+""+arr[1]+""+""+arr[2]+""+")"+"-"+arr[3]+""+""+arr[4]+""+""+arr[5]+"-"+arr[6]+""+""+arr[7]+""+""+arr[8]+""+arr[9]);
}
}

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