Question

Letter to Number Converter: Create a program that reads a phone number as letters from a...

Letter to Number Converter:

Create a program that reads a phone number as letters from a variable and converts it to numbers
e.g. GET-LOAN = 438-5626
When the company uses more than 7 letters, it should convert it to 7 digits
e.g. CALL-HOME = 225-5466
The resulting converted number should include the dash to separate the three digits from the four digits

Hint: Use the String object charAt method to read the variable that is storing the phone number as letters.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOURCE CODE:

import java.util.Scanner;
public class letters
{
static int num(char a)
{
switch(a)
{
case 'a':
case 'b':
case 'c':
case 'A':
case 'B':
case 'C':
return 2;
case 'D':
case 'E':
case 'F':
case 'd':
case 'e':
case 'f':
return 3;
case 'g':
case 'h':
case 'i':
case 'G':
case 'H':
case 'I':
return 4;
case 'j':
case 'k':
case 'l':
case 'J':
case 'K':
case 'L':
return 5;
case 'm':
case 'n':
case 'o':
case 'M':
case 'N':
case 'O':
return 6;
case 'p':
case 'q':
case 'r':
case 's':
case 'P':
case 'Q':
case 'R':
case 'S':   
return 7;
case 't':
case 'u':
case 'v':
case 'T':
case 'U':
case 'V':
return 8;
case 'w':
case 'x':
case 'y':
case 'z':
case 'W':
case 'X':
case 'Y':
case 'Z':   
return 9;
}
return 0;
}
public static void main(String args[])
{
String a;
int b[]=new int[8];
int i,j=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter letters");
a=sc.next();
for(i=0;i<8;i++)
{
if(a.charAt(i)=='-')
;
else
{
b[j]=num(a.charAt(i));
j++;
}
/*b[i]=0;
else
b[i]=num(a.charAt(i));*/
}
j=0;
System.out.println("The number is : ");
for(i=0;i<8;i++)
{
if(i==3)
System.out.print("-");
else
{
System.out.print(b[j]);
j++;
}
}
}
}

SCREENSHOTS:

letters Class Edit Tools Options letters X Compile Undo Cut Copy Paste Find.. Close Source Code import java.util.Scanner; pubEnter letters CALL-HOME The number is: 225-5466Enter letters GET-LOAN The number is: 438-5626

Add a comment
Know the answer?
Add Answer to:
Letter to Number Converter: Create a program that reads a phone number as letters from a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The skeleton code (starter file) for the problem is pasted below: def phoneNumber(letters): result = ""...

    The skeleton code (starter file) for the problem is pasted below: def phoneNumber(letters): result = "" # ADD YOUR CODE HERE return result def loadEvents(filename): events = {} # ADD YOUR CODE HERE return events def timeline(events): # ADD YOUR CODE HERE return # DO NOT modify or remove the code below! We will use it for testing. if __name__ == "__main__": # Problem 1: Decoding Telephone Numbers ph = input("Enter the text to translate: ") print("The corresponding phone number...

  • 4B : C PROGRAMMING To make telephone numbers easier to remember, some companies use letters to...

    4B : C PROGRAMMING To make telephone numbers easier to remember, some companies use letters to show their telephone number. For example, using letters & spaces, 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 program that prompts the user to enter a telephone number expressed in letters/spaces and...

  • Regular C Programming It is just a random generator of telephone numbers DESCRIPTION To make telephone...

    Regular C Programming It is just a random generator of telephone numbers DESCRIPTION To make telephone numbers easier to remember, some companies use letters to show their telephone number, but mapping the letters to the numbers on a standard telephone keypad: 1 2 ABC 3 DE 4G 5 11 6 MNO 7 PONS 8 Tu 9.xyz # For example, using letters & spaces, the telephone number 438-5626 can be shown as GET LOAN. In some cases, to make a telephone...

  • To make telephone numbers easier to remember, some companies use letters to show their telephone number....

    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 see more than seven letters. For example, 255-5466 can be displayed as CALL HOME, which uses eight letters. Write a program that prompts the user to enter a telephone expressed in letters and outputs the corresponding telephone number in...

  • Programming Concepts CS 225 for C++ To make telephone numbers easier to remember, some companies use...

    Programming Concepts CS 225 for C++ To make telephone numbers easier to remember, some companies use digits and letters (or only letters) to show their telephone number. In some cases, to make a telephone number meaningful, companies might use more than seven digits and letters. Here are some examples: Phone Number in Display Note Actual Phone Number GET LOAN - 438-5626 CALL HOME More than seven digits/letters used for ease of remembrance. 225-5466 111 GOLD - 111-4653 Glass4u - 452-7748...

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • I don't know how to terminate the code in the second time that whether or not...

    I don't know how to terminate the code in the second time that whether or not the users want to continue to get a new number. PLEASE HELP. 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 might use more than seven letters. For example, 225-5466 can be displayed...

  • C Program In this assignment you'll write a program that encrypts the alphabetic letters in a...

    C Program In this assignment you'll write a program that encrypts the alphabetic letters in a file using the Vigenère cipher. Your program will take two command line parameters containing the names of the file storing the encryption key and the file to be encrypted. The program must generate output to the console (terminal) screen as specified below. Command Line Parameters Your program must compile and run from the command line. The program executable must be named “vigenere” (all lower...

  • General Requirements . . . Write a program that reads letters from a file called "letters.txt"....

    General Requirements . . . Write a program that reads letters from a file called "letters.txt". Your program will open the letters.txt file read in one character at a time For this assignment the test file will contain at least 30 letters, uppercase OR lowercase In your program you will change each letter (solution) to uppercase Use the function toupper in #include <ctype.h> You create a numerical version of the uppercase letter from the file . o Use int numberSolution...

  • build a phone number from digits entered by your user. Your program will loop until 10...

    build a phone number from digits entered by your user. Your program will loop until 10 valid digits have been entered. It will then use those digits to display the phone number entered using the format: XXXXXXXXXX (or (XXX) XXX – XXXX for extra credit). The program will ask for a digit, it will check to see if the digit is actually between 0 and 9 inclusively. If so, the digit will be stored as the next number in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT