In: Computer Science
You are supposed to write Java program for the following questions. For every question, do provide at least THREE (3) different test cases. Question 1 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.
Copyable Code:
import java.util.Scanner;
public class assignProgram
{
public static void main(String args[])
{
String number;
char c;
Scanner in = new
Scanner(System.in);
for(;;)
{
System.out.print("\nEnter the phone number that is in letters or
for quit enter 0: ");
number =
in.nextLine();
if(number.equals("0"))
{
break;
}
for(int i = 0; i
< 8; i++)
{
c = number.charAt(i);
if(i == 3)
System.out.print("-");
if(c >= 'A' && c <= 'Z' || c >=
'a' && c <='z')
{
switch(c)
{
case 'A':
case 'a':
case 'B':
case 'b':
case 'C':
case 'c':
System.out.print("2");
break;
case 'D':
case 'd':
case 'E':
case 'e':
case 'F':
case 'f':
System.out.print("3");
break;
case 'G':
case 'g':
case 'H':
case 'h':
case 'I':
case 'i':
System.out.print("4");
break;
case 'J':
case 'j':
case 'K':
case 'k':
case 'L':
case 'l':
System.out.print("5");
break;
case 'M':
case 'm':
case 'N':
case 'n':
case 'O':
case 'o':
System.out.print("6");
break;
case
'P':
case 'p':
case 'Q':
case 'q':
case 'R':
case 'r':
case 'S':
case 's':
System.out.print("7");
break;
case
'T':
case 't':
case 'U':
case 'u':
case 'V':
case 'v':
System.out.print("8");
break;
case
'W':
case 'w':
case
'X':
case
'x':
case 'Y':
case 'y':
case 'Z':
case 'z':
System.out.print("9");
break;
}
}
}
}
}
}