Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with this program import java.util.Scanner; public class Telephone { public static int getIntForAlphaNumeric(char c) { if (c == 'S') { c =
I need help with this program
import java.util.Scanner;
public class Telephone {
public static int getIntForAlphaNumeric(char c)
{
if (c == 'S')
{
c = 'R';
}
if (c == 'Z')
{
c = 'Y';
}
int i = Character.getNumericValue(c) - Character.getNumericValue('A')+1 ;
return (int) (Math.ceil(i/3.0) + 1);
}
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a telephone number: ");
String line = sc.nextLine();
line = line.replaceAll("\\s+","");
line = line.toUpperCase();
for(int i = 0; i
To make telephone numbers easier to remember, some companies user 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 might use more than seven letters. For example 225-5466 can be displayed as CALL HOME, which uses eight letters. Write a Java 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 that seven letters (spaces do not count), then process only the first seven letters and ignore the rest. Your program should also output the (hyphen) after the third digit. Allow the user to use uppercase and lowercase letters, as well as spaces between the words. Hint: You can read the entered telephone number as a String and then use the charAt method of the class String to extract each character. For example, if str refers to your String. then the expression str.charAt (i) returns the character at the position. Recall that in a string, the position of the first character is 0. If the user enters Get Loan Your program will output: 438-5626 Or, if the user enters: CAll HoMe Your program will output: 225-5466 Your prompt to the user should be: Please enter a telephone number using letters: Please note that your class should be named TelephoneNumber {
System.out.print(getIntForAlphaNumeric(line.charAt(i)));
}
System.out.print("-");
for(int i = 3; i
{
System.out.print(getIntForAlphaNumeric(line.charAt(i)));
}
System.out.println();
}
}
for this program when i insert
they called
i get
843-10225
Expected output
Please enter a telephone number using letters :
843-9225
LovE Java
Your output
Please enter a telephone number using letters :
569-3529
Expected output
Please enter a telephone number using letters :
568-3528
I am Having FUN
Your output
Please enter a telephone number using letters :
426-4294
Expected output
Please enter a telephone number using letters :
426-4284
please help me fix my program so I get the expected outputs! when the user enters these 3 sentences.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started