|
home—info—labs—hws—exams
textbook—java.lang docs—java.util docs—archive
Due Nov.12 (Wed).
This is an individual homework: Although it uses work from lab09b—Pig La(b)tin I (If you want it, here is a pig-latin solution, as given-and-fixed-up in lab10b—debugging), you are not to work with your lab partner. (As ever, you can discuss the problem and approaches with others, but you have to write the code entirely on your own.)
For this assignment, we'll write a program which translates an entire message into Pig Latin. We'll start with the file we wrote in lab09b—Pig La(b)tin I, and add more methods to it. (Be sure you got a copy of that file which you and your lab partner worked on; alternately, a solution will be provided here soon.)
By the way, we will not duplicate code from that program; instead, we'll repeatedly call that method to translate a single word. Ere'shay owhay:
Write a method which tells the user to enter a message, and then translates the message to Pig Latin. Finally, your program finishes by reporting: (a) how many words were translated total, and (b) how many total characters of punctuation were processed.
For example, here's a possible transcript, where the user's input is shown in green:
Enter a message to be translated: Four score and seven years ago, our ourFay orescay anday evensay earsyay ago,ay ouray forefathers did orefathersfay idday some pretty rad stuff. omesay ettypray adray uff.stay control-D 13 words and 2 punctuation marks handled. |
Here's another input; note how our program reports “1 word …”, and not the (grammatically incorrect) “1 words …”:
Enter a message to be translated: Aloha,ha,ha...? control-D Aloha,ha,ha...?ay 1 word and 6 punctuation marks handled. |
Note: the methods you wrote in lab should occur once in your program. If you want to convert a word into pig latin, call the method from lab, rather than writing/pasting any of that code again.
For example, here's a possible transcript, where the user's input is shown in green:
Enter a message to be translated: Four score and seven years ago, our forefathers did some pretty rad stuff. control-D ourFay orescay anday evensay earsyay ago,ay ouray orefathersfay idday omesay ettypray adray uff.stay stuff. rad pretty some did forefathers our ago, years seven and score Four 13 words and 2 punctuation marks handled. |
Here's another input; note how our program reports “1 word …”, and not the (grammatically incorrect) “1 words …”:
Enter a message to be translated: Aloha,ha,ha...? control-D Aloha,ha,ha...?ay Aloha,ha,ha...? 1 word and 6 punctuation marks handled. |
There are many ways to improve this assignment. We'll offer some extra-credit, but don't start working on these until you have your regular program fully working. You can do any of these options; you don't need to do A before trying B, etc..
It turns out, having a scanner read from a web page (rather than System.in) is easy. However, web pages are more than just words of text; web pages contain markup to indicate the structure of the document (where emphasized text should start and end, where to insert horizontal lines, etc.). Thus, web pages are written in “HTML” — “hypertext markup language”. We need to translate the regular information into pig latin, but leave this markup information untouched.
More information you need is here.
1 Doing this would require something fancier than Scanner's next(): perhaps calling nextLine(), and then reading information from that String by creating a (second) Scanner which gets its input not from the keyboard, but from that String. ↩
2 The user can indicate end-of-input by typing typing Control-D on a line by itself. Note that the Scanner method hasNext usually returns true; it only returns false when the input is finished (that is, when the user has typed control-D). ↩
3 For this extra credit, we won't consider (or worry about) words which have more than one punctuation character. ↩
home—info—labs—hws—exams
textbook—java.lang docs—java.util docs—archive
©2008, Ian Barland, Radford University Last modified 2008.Nov.20 (Thu) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |