Question

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 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.

* Java program free from syntax, logic and run time errors

* Used appropriate String and Character methods to handle blank spaces, digits, letters and others.

* Code optimisation: no unnecessary variables, if statements and counters.

* Shown with 3 Cases (at least one with blank spaces etc.). Descriptive block and inline comments included

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

Answer:--                                                                   Date:--27/02/2019

FILE NAME:CONVERSION.JAVA

import java.util.Scanner;

public class Conversion {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Scanner sc=new Scanner(System.in);
       int sum = 0;
       System.out.println("enter the input :");
       String input=sc.nextLine();
       String sb=input.toLowerCase();
       for(int i=0;i<sb.length();i++)
       {
           if (sb.charAt(i) != ' ' && sb.charAt(i) >= 'a' && sb.charAt(i) <= 'z' && sb.charAt(i) >= 'A' && sb.charAt(i) <= 'z') sum++;
         
         
           if(sum == 4) {System.out.print("-");}
         
       switch (sb.charAt(i)) {
         
       case 'a':
       case 'b':
       case 'c':
       System.out.print( "2");
       break;
       case 'd':
       case 'e':
       case 'f':
       System.out.print( "3");
       break;
       case 'g':
       case 'h':
       case 'i':
       System.out.print( "4");
       break;
       case 'j':
       case 'k':
       case 'l':
   System.out.print( "5");
       break;
       case 'm':
       case 'n':
       case 'o':
           System.out.print( "6");
       break;
       case 'p':
       case 'q':
       case 'r':
       case 's':
       System.out.print( "7");
       break;
       case 't':
       case 'u':
       case 'v':
       System.out.print( "8");
       break;
       case 'w':
       case 'x':
       case 'y':
       case 'z':
       System.out.print( "9");
       System.out.print( "\n");
       break;
  
       default:
           System.out.print( "9");
       }
       }
       sc.close();
   }
  

}

Add a comment
Know the answer?
Add Answer to:
To make telephone numbers easier to remember, some companies use letters to show their telephone number....
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
  • 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...

  • 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...

  • 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...

  • read all pls Assessment 1: Individual Assignment Weightage Submission Deadline Word Limit 30% TBA NA Assignment...

    read all pls Assessment 1: Individual Assignment Weightage Submission Deadline Word Limit 30% TBA NA Assignment Topic and Requirements 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 Please use netbeans! joptionpane needed! Question 3 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...

  • 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...

  • 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...

  • Help with programming in Raptor: Many companies use telephone numbers like 555-GET-FOOD so the number is...

    Help with programming in Raptor: Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On a standard telephone, the alphabetic letters are mapped to numbers in the following fashion: A, B, and C = 2 D, E, and F = 3 G, H, and I = 4 J, K, and L = 5 M, N, and O = 6 P, Q, R, and S = 7 T, U, and V = 8...

  • Write a program that prompts for a sentence and calculates the number of uppercase letters, lowercase...

    Write a program that prompts for a sentence and calculates the number of uppercase letters, lowercase letters, digits, and punctuation. Output the results neatly formatted and labeled in columns. how I can make this program in a more simple way. # get user input user_string = input("Enter a sentence: ") # create and initialize variables upper_case = 0 lower_case = 0 digits = 0 spaces = 0 punctuations = 0 x = len(user_string) #loop conditions and increment for i in...

  • 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...

  • 6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you...

    6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...

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