I need help on the modification part at the bottom. To make telephone numbers ea
ID: 671792 • Letter: I
Question
I need help on the modification part at the bottom.
To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone number meaningful, companies must use more than seven letters. For example, 225-5466 can be displayed as CALL HOME, which uses eight letters. Write a program that prompts the user to enter a telephone number expressed in letters and outputs the corresponding telephone number in digits. If the user enters more than seven letters, then process only the first seven letters. Also output the – (hyphen) after the third digit. Allow the user to use both uppercase and lowercase letters as well as spaces between words.
import java.util.Scanner;
public class AssignmentQ3 {
public static void main(String[] args)
{String number;
int i=0,j=0,len;
char c;
Scanner in=new Scanner (System.in);
do
{i=0;
j=0;
System.out.println("Enter the phone number: ");
number=in.nextLine();
number=number.toUpperCase();
len=number.length();
while(i<len&&j<8)
{c=number.charAt(i);
switch(c)
{case 'A':case 'B':case 'C':
System.out.print("2");
j++;
break;
case 'D':case 'E':case 'F':
System.out.print("3");
j++;
break;
case 'G':case 'H':case 'I':
System.out.print("4");
j++;
break;
case 'J':case 'K':case 'L':
System.out.print("5");
j++;
break;
case 'M':case 'N':case 'O':
System.out.print("6");
j++;
break;
case 'P':case 'R':case 'S':
System.out.print("7");
j++;
break;
case 'T':case 'U':case 'V':
System.out.print("8");
j++;
break;
case 'W':case 'X':case 'Y':
System.out.print("9");
j++;
break;
}
if(j==3)
{System.out.print("-");
j++;
}
i++;
}
System.out.print(" Do it again(Y/N)? ");
number=in.nextLine();
number=number.toUpperCase();
}while(number.charAt(0)=='Y');
}
}
Modify question 3 of Assignment 1 to accept a telephone number with any number of letters. The output should display a hyphen after the first 3 digits and subsequently a hyphen (-) after every four digits. Also, modify the program to process as many telephone numbers as the user wants.
Explanation / Answer
#include using namespace std; int main(){ int counter; char phoneNumber; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.