Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Program help!!!!! Description: Standard telephone keypads containe the digi

ID: 3688605 • Letter: J

Question

Java Program help!!!!!

Description:

Standard telephone keypads containe the digits zero through nine. The numbers two through nine each have three letters associated with them. 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 remember it as "NUMBERS".

Each seven-letter word or word combination corresponds to exactly one seven-digit telephone number, but a seven-digit number corresponds to many seven-letter words, most of which are not English words. It is possible, for example, that the owner of a barbershop would be pleased to know that the shop's telephone number 424-7288 corresponds to "HAIRCUT", or a liquor store's number 233-7226 corresponds to "BEERCAN".

Objective:

Write a program that asks a user to enter a seven-digit phone number and then writes to the file 'numbers.txt' every possible seven-letter word combination corresponding to that number. There are 2187 (i.e. 37) such combinations. Treat the digits 0 & 1 as spaces, and the rest as shown:

Digit | Letters 1[space] 2 3 4. 5 6 A B C D E F G H I J K L M N O P R S [space]

Explanation / Answer

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package phonenumber;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.PrintStream;
import java.util.Scanner;

/**
*
* @author murarji
*/
public class Phonenumber {

/**
* @param args the command line arguments
*/
static String phoneNumber;
static char numberLetters[][] = {
{'0','0','0'},{'1','1','1'},{'A','B','C'},
{'D','E','F'},{'G','H','I'},{'J','K','L'},
{'M','N','O'},{'P','R','S'},
{'T','U','V'},{'W','X','Y'}};


static Scanner input = new Scanner (System.in);
static private ObjectOutputStream output;
static PrintStream printStream;
static char[] word = new char [7];

public static void main(String[] args) {
// TODO code application logic here
System.out.println("Enter a seven-digit telephone number: ");
phoneNumber = input.next();
openFile();
addFileInfo();
closeFile();
}
  
public static void openFile()
{
try // open file
{
output = new ObjectOutputStream(
new FileOutputStream ( "Phonenumber.txt") );

}// end try
catch ( IOException ioEcception )
{
System.err.println( "Error opening file.");
} // end catch
}// end method open file
  
public static void addFileInfo( )
{
try
{
char[] chars = phoneNumber.toCharArray ();
int [] digit = new int [chars.length];
for (int i = 0; i < chars.length; i++)
{
digit[i] = Integer.parseInt(String.valueOf(chars[i]));
}

printStream = new PrintStream(output);
printStream.println(" ");


for ( int level0 = 0; level0 < 3; level0 ++ )
{
word[0] = numberLetters[digit[0]][level0];

for ( int level1 = 0; level1 < 3; level1 ++ )
{
word[1] = numberLetters[digit[1]][level1];

for ( int level2 = 0; level2 < 3; level2 ++ )
{
word[2] = numberLetters[digit[2]][level2];

for ( int level3 = 0; level3 < 3; level3 ++ )
{
word[3] = numberLetters[digit[3]][level3];

for ( int level4 = 0; level4 < 3; level4 ++ )
{
word[4] = numberLetters[digit[4]][level4];

for ( int level5 = 0; level5 < 3; level5 ++ )
{
word[5] = numberLetters[digit[5]][level5];

for ( int level6 = 0; level6 < 3; level6 ++ )
{
word[6] = numberLetters[digit[6]][level6];
printStream.print(word);
}
}
}
}
}
}
}

System.out.println("File written.");
System.exit(1);

}
catch (Exception exception )
{
System.err.println( "Error writing to file.");
System.exit(1);
}
}
  
public static void closeFile()
{
try // close file
{
if ( output != null )
output.close();
}// end try
catch (IOException ioException )
{
System.err.println( "Error closing file.");
System.exit(1);
}// end catch


}// end method closeFile
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote