Question
In Java: (Telephone-Number WordGenerator) Standard telephone keypads containthe digits zero through nine. The numbers two through nine eachhave three letters associated with them Fig.1 below.
In Java:
(Telephone-Number WordGenerator) Standard telephone keypads containthe digits zero through nine. The numbers two through nine eachhave three letters associated with them Fig.1 below. Many people find it difficult to memorizephone numbers, so they use the correspondence between digits andletters to develop seven-letter words that correspond to theirphone numbers. For example, a person whose telephone number is686-2377 might use the correspondence indicatedin Fig. 1 todevelop the seven-letter word “NUMBERS.” Every seven-letter wordcorresponds to exactly one seven-digit telephone number. Arestaurant wishing to increase its takeout business could surely doso with the number 825-3688 (i.e., “TAKEOUT”).
Every seven-letter phone number corresponds to many differentseven-letter words, but most of these words representunrecognizable juxtapositions of letters. It’s possible, however,that the owner of a barbershop would be pleased to know that theshop’s telephone number, 424-7288, corresponds to “HAIRCUT.” Aveterinarian with the phone number 738-2273 would be pleased toknow that the number corresponds to the letters “PETCARE.” Anautomotive dealership would be pleased to know that the dealershipnumber, 639-2277, corresponds to “NEWCARS.”
Digit | Letters | Digit | Letters | Digit | Letters |
2 | A B C | 5 | J K L | 8 | T U V |
3 | D E F | 6 | M N O | 9 | W X Y |
4 | G H I | 7 | P R S |
Fig. 1 Telephone keypad digits and letters.
Write a program that, given a seven-digit number, uses aFormatter object to write to a file every possible seven-letterword combination corresponding to that number. There are 2,187(37)(37) such combinations. Avoid phone numbers with the digits 0and 1.
Use the following test class to test your program:
import java.util.Scanner;
import java.util.NoSuchElementException;
public class PhoneTest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Phone application = new Phone();
System.out.print(
"Enter phone number (digitsgreater than 1 only): ");
try {
application.calculate(scanner.nextInt());
}
catch (NoSuchElementExceptionelementException) {
System.err.println("Errorinputting data.");
}
}
}
Step by Step Solution
3.39 Rating (149 Votes )
There are 3 Steps involved in it
Step: 1
Heres a solution to the problem java import javaioFile import javaioFileNotFoundException import javautilFormatter import javautilNoSuchElementExcepti...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