Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Hello, I need help with completing my code in Java according to the instructions below. A sample output would be helpful. I have posted so

Hello, I need help with completing my code in Java according to the instructions below. A sample output would be helpful. I have posted so far and I want to complete based on what I myself have written so far but if any differences need to be made then that is alright, I want to be able to understand a working program on how to do this per the instructions. Thank you very much ma'am or sir.

THESE ARE THE INSTRUCTIONS

(Telephone-Number Word Generator) Standard telephone keypads contain the digits zero through nine. The numbers two through nine each have three letters associated with them Fig. 1below. Many people find it difficult to memorize phone numbers, so they use the correspondence between digits and letters to develop seven-letter words that correspond to their phone numbers. For example, a person whose telephone number is 686-2377 might use the correspondence indicated in Fig. 1 to develop the seven-letter word NUMBERS. Every seven-letter word corresponds to exactly one seven-digit telephone number. A restaurant wishing to increase its takeout business could surely do so with the number 825-3688 (i.e., TAKEOUT).

Every seven-letter phone number corresponds to many different seven-letter words, but most of these words represent unrecognizable juxtapositions of letters. Its possible, however, that the owner of a barbershop would be pleased to know that the shops telephone number, 424-7288, corresponds to HAIRCUT. A veterinarian with the phone number 738-2273 would be pleased to know that the number corresponds to the letters PETCARE. An automotive dealership would be pleased to know that the dealership number, 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 a Formatter object to write to a file every possible seven-letter word combination corresponding to that number. There are 2,187 (37)(37) such combinations. Avoid phone numbers with the digits 0 and 1.

THIS IS THE PROGRAM I NEED TO USE TO TEST MINE WITH

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 (digits greater than 1 only): ");

try { application.calculate(scanner.nextInt()); } catch (NoSuchElementException elementException) { System.err.println("Error inputting data."); } }

THIS IS WHAT I HAVE CODED SO FAR BUT NEED HELP WITH FINISHING

import java.io.FileNotFoundException;

import java.lang.SecurityException;

import java.util.FormatterClosedException;

import java.util.NoSuchElementException;

import java.util.Formatter;

public class Phone

{

private static Formatter output;//Outputs text to a file

public static void main(String[] args) throws FileNotFoundException

{

openFile();

addToFile(null);//Will write every possible combination to file

closeFile();

}

private static void openFile() throws FileNotFoundException

{

try

{

output=new Formatter("KeypadCombinations.txt");

System.exit(1);//Terminates the program

}

catch(SecurityException securityException)

{

System.err.println("ERROR: No permission to write to file.");//Error explanation

System.exit(1);//Terminates the program

}

}

private static void addToFile(String Combinations)

{

Phone application = new Phone();

}

public void calculate(int nextInt)

{

//One dimenstional arrays that will store letters similar to phone keypad

char[] two=('A', 'B', 'C');

char[] three=('D', 'E', 'F');

char[] four=('G', 'H', 'I');

char[] five=('J', 'K', 'L');

char[] six=('M', 'N', 'O');

char[] seven=('P', 'R', 'S');//Excluded 'Q' according to chart keypad instructions in instructions comment

char[] eight=('T', 'U', 'V');

char[] nine=('W', 'X', 'Y');//Excluded 'Z' according to chart keypad instructions in instructions comment

//One dimensional arrays to store the letters

char position1[] = new char[3];

char position2[] = new char[3];

char position3[] = new char[3];

char position4[] = new char[3];

char position5[] = new char[3];

char position6[] = new char[3];

char position7[] = new char[3];

}

public static void closeFile()//Closes file after completion of adding combinations to file

{

if(output!=null)//If the file has combinations added...

output.close();//Proceed with closing the file

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students explore these related Databases questions

Question

What does this public need on this issue?

Answered: 3 weeks ago