Question
JAVA Write a Java program that encodes English-language phrases into pig-Latin. You will scan text in from a text file. The text at the end
JAVA
Write a Java program that encodes English-language phrases into pig-Latin.
You will scan text in from a text file. The text at the end of this post:
Pig-Latin is a form of coded language often used for amusement.
For simplicity, use the following algorithm:
To form a Pig-Latin phrase from an English-language phrase, tokenize the phrase into words.
Place the first letter of the English word at the end of the English word and add the letters ay.
Thus the word jump becomes umpjay, the word the becomes hetay and the word computer becomes omputercay.
Blanks and punctuation marks between words remain unchanged. If a word in the English phrase was capitalized you will have to change the case of the Pig-Latin phrase accordingly. Thus the word Professor would become Rofessorpay.
Scan in from a text file you create
At the end of your program print the following statistics:
1. The number of words in the original text. 2. The number of letter in the original text. 3. The number of punctuation marks in the original text. 4. The number of whitespace characters in the original text. 5. The number of all characters in the original (including punctuation, digits, and whitespace.)
METHODS
1. Write a method, convertWord, which given a word in English returns the equivalent word in Pig- Latin.
2. Write a method, processWords, which reads a word one at a time from the input file and sends it to the convertWord method. After returning from the convertWord method the processWords method should print the word and after all words have been processed, print the number of words processed by the method. Print 10-words per line. It should then close the input file.
3. Write a method, countItemsInFile, which reopens the original input file. This method should read an entire line at a time from the file, processing each character in the string to determine if it is a letter, digit, punctuation mark, or whitespace. It then prints the results.
4. The main method invokes the processWords method and then invokes the countItemsInFile method.
TEXT FILE
To be, or not to be, that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles And by opposing end them. To dieto sleep, No more; and by a sleep to say we end The heart-ache and the thousand natural shocks That flesh is heir to: 'tis a consummation Devoutly to be wish'd. To die, to sleep; To sleep, perchance to dreamay, there's the rub: For in that sleep of death what dreams may come, When we have shuffled off this mortal coil, Must give us pausethere's the respect That makes calamity of so long life.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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