Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java Programming II Homework 4 To make telephone numbers easier to remember, some companies user letters to show their telephone number. For example, using letters,

Java Programming II Homework 4

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.

Hint1: You can 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 ith position. Recall that in a String, the position of the first character is 0.

Hint2: You can use the toUpperCase or toLowerCase method of the class String to convert all chars in the String to upper or lower.

Hint3:

Number Letter
0 none
1 none
2 ABC
3 DEF
4 GHI
5 JKL
6 MNO
7 PQRS
8 TUV
9 WXYZ
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".

Submission Instructions

'TelephoneNumber.java'

Compile command: javac TelephoneNumber.java -Werror -Xlint:all

We will use this command to compile your code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions