Question & Answer: efore "smart phones" mobile phones used the numeric keypad to compose text messages. This was accomplished a couple different w…..

efore “smart phones” mobile phones used the numeric keypad to compose text messages. This was accomplished a couple different ways. ACMIA phones took a numeric code, consulted its dictionary of known words with that code, and offered choices for what that word might be. Consider the following table:

1 2 abc 3 def
4 ghi 5 jkl 6 mno
7 pqrs 8 tuv 9 wxyz
0 (space)

So, 263 might be and, 748 might be sit, or pit, 666 might be mom, or non, etc.

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: efore "smart phones" mobile phones used the numeric keypad to compose text messages. This was accomplished a couple different w…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

Your task is to write a program that displays all possible matches for given digit sequences, using a given dictionary (list of words).

Input

Your program first will read a file whose name is stored in the environment variable ACMIA_WORDS , compute the codes for each word, and store the (code, word) pair in a dictionary. (Careful! Each code may have several words that match it. Build your dictionary appropriately). The words file has one word per line.

You needn’t worry about words containing spaces, numbers, nor a ‘, as might be found in contractions, nor other punctuation. Capital letters, however, are fair game.

Here is a sample word list, has about 10,000 words in it.

You will then read from stdin a sequence of “phrases”, numberic codes, one phrase per line, and print out the translated phrase, with word choices indicated, as shown below.

Words will be separated by one or more spaces, indicated in the code by a zero (0) . Multiple consecutive zeroes will be treated as a single space. Leading and trailing zeroes will be ignored.

Read every line of input. Do not prompt for responses.

Output

You will decode each line of input, and write the decoded phrase to stdout

For each line read (for each code), for each sequence of non-zero digits, display the matching word from the dictionary. When more than one match is available, display all matches in lexical order between parentheses, separated by bars. If there is no matching word, display a sequence of asterisks of the same length.

So, given a word list:

chocolate
I
hear
loud
love
programming

, and the sequence:

0040568300077647266464077770

, you would output, on a single line:

I (loud|love) programming ****

You will output a single line for every line of input, no blank lines (unless a blank line is input).

Ant

Create an ant build file that has a target called run, which will run your program, making sure that it is first compiled.

Your buildfile will contain, minimally, the following targets:

run – runs your program. No environment variables to worry about

clean – removes all intermediate (*.class) files from the directory

Whatever other targets/dependencies you want to put in there, great.

Expert Answer

 

//main.java

import java.io.*;

import java.util.*;

public class PhoneDict

{

public static void main( String[] args )

{

String filepath = System.getenv( “ACMIA_WORDS” );

HashMap<String, List<String>> hmWords = new HashMap<String,

List<String>>();

try

{

String line;

String code = “”;

File test= new File(filepath);

if (test.exists() )

{

// ========== Read File, Create Map ================== //

new FileReader( filepath );

BufferedReader br = new BufferedReader( new FileReader( filepath ) );

while( (line = br.readLine() ) != null )

{

System.out.println( line );

//reads each char, uses func to convert to code

for( int i = 0; i < line.length(); ++i )

{

code += charToCode( line.toLowerCase().charAt(i) );

}

//stores to hashmap, checks that code is not stored twice

if(!hmWords.containsKey(code))

{

hmWords.put( code, new ArrayList<String>() );

}

hmWords.get(code).add(line);

code = “”;

}

}

else

{

System.out.println( “Error: No file to read…” );

}

// =========== Read from Stdin =========== //

InputStreamReader in = new InputStreamReader( System.in );

BufferedReader input = new BufferedReader( in );

String phrase;

String translation=””;

String[] parts;

while( (phrase = input.readLine()) != null )

{

parts = phrase.split( “(0+)” );

for( int i = 0; i < parts.length; ++i )

{

System.out.println( parts[i] );

if( !hmWords.containsKey( parts[i] ) )

{

System.out.println( “” );

}

else if( hmWords.get(parts[i]).size() > 1)

{

translation += “(“;

for( int j = 0; j < hmWords.get(parts[i]).size(); ++j )

{

if( j == (hmWords.get(parts[i]).size() – 1) )

{

translation+= hmWords.get(parts[i]).get(j);

}

else

{

translation += hmWords.get(parts[i]).get(j) + “|”;

}

}

translation += “)”;

}

else

{

translation += hmWords.get(parts[i]).get(i) + ” “;

}

}

System.out.println( translation );

translation=””;

}

}

catch( Exception except )

{

System.out.println( except.getMessage() );

}

}

// ——————- FUNCTION ——————-

//takes char and returns to respective number on Number Pad as char

public static char charToCode( char word )

{

if( word==’a’ || word==’b’ || word==’c’ )

{

return ‘2’;

}

else if( word==’d’ || word==’e’ || word==’f’ )

{

return ‘3’;

}

else if( word==’g’ || word==’h’ || word==’i’ )

{

return ‘4’;

}

else if( word==’j’ || word==’k’ || word==’l’ )

{

return ‘5’;

}

else if( word==’m’ || word==’n’ || word==’o’ )

{

return ‘6’;

}

else if( word==’p’ || word==’q’ || word== ‘r’ || word==’s’ )

{

return ‘7’;

}

else if( word==’t’ || word==’u’ || word==’v’ )

{

return ‘8’;

}

else if( word==’w’ || word==’x’ || word== ‘y’ || word==’z’ )

{

return ‘9’;

}

else

{

return ‘0’;

}

}

}

Grand Paper Writers
Order NOW For A 10% Discount!
Pages (550 words)
Approximate price: -

Our Advantages

Plagiarism Free Papers

All papers are written by the best professional writers to ensure 100% originality. We always provide plagiarism reports whenever we deliver completed papers.

Free Revisions

All papers by Grand Paper Writers are completed and submitted on time. This timely delivery of papers gives you time to go through the paper before the official deadline.

Title-page

As an additional service, we will provide a title page that precedes the contents of your paper. Here, you will provide your personal details.

Bibliography

We also ensure that we provide an extra page for the references or bibliographies following referencing rules.

Originality & Security

At Grandpaperwriters.com, we guarantee students for the provision of security and original work. All your personal information is handled with confidentiality and is not shared with third parties. Additionally, we ensure that we provide original content with accompanying plagiarism reports to show originality.

24/7 Customer Support

Our customer support team is always available 24/7 to provide instant responses to any queries raised by students.

Try it now!

Calculate the price of your order

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Grandpaperwriters.com has the best professional essay writers for quality services.

Pricing

Flexible Pricing

Here, a Grandpaperwriters.com, we do not compromise on the time of our clients. We always deliver all completed papers on or before the deadlines.

Communication

Admission Help & Client-Writer Contact

Grandpaperwriters.com provides an interactive portal where students can communicate directly to their writers.

Deadlines

Paper Submission

Here, a Grandpaperwriters.com, we do not compromise on the time of our clients. We always deliver all completed papers on or before the deadlines.

Reviews

Customer Feedback

Grandpaperwriters.com appreciates feedback from our clients to help us improve the delivery of essay writing services. As such, we are constantly changing our policies to ensure maximum customer and writer satisfaction.