/** * Translates a sentence into pig latin. */ public class PigLatinTranslator {
/** To use for input. */ private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in));
/** Main method */ public static void main(String[] args) throws IOException {
// Get a string System.out.print("Enter sentence: "); String english = getString();
// Translate and print back out String latin = pigLatin(english); System.out.println(latin); }
/** * Method to translate a sentence word by word. * @param s The sentence in English * @return The pig latin version */ private static String pigLatin(String s) { String latin = ""; int i = 0; while (i<s.length()) {
// Take care of punctuation and spaces while (i<s.length() && !isLetter(s.charAt(i))) { latin = latin + s.charAt(i); i++; }
// If there aren't any words left, stop. if (i>=s.length()) break;
// Otherwise we're at the beginning of a word. int begin = i; while (i<s.length() && isLetter(s.charAt(i))) { i++; }
// Now we're at the end of a word, so translate it. int end = i; latin = latin + pigWord(s.substring(begin, end)); } return latin; }
/** * Method to test whether a character is a letter or not. * @param c The character to test * @return True if it's a letter */ private static boolean isLetter(char c) { return ( (c >='A' && c <='Z') || (c >='a' && c <='z') ); }
/** * Method to translate one word into pig latin. * @param word The word in english * @return The pig latin version */ private static String pigWord(String word) { int split = firstVowel(word); return word.substring(split)+"-"+word.substring(0, split)+"ay"; }
/** * Method to find the index of the first vowel in a word. * @param word The word to search * @return The index of the first vowel */ private static int firstVowel(String word) { word = word.toLowerCase(); for (int i=0; i<word.length(); i++) if (word.charAt(i)=='a' || word.charAt(i)=='e' || word.charAt(i)=='i' || word.charAt(i)=='o' || word.charAt(i)=='u') return i; return 0; }
/** * Helper method to get input. * @return A String from stdout */ private static String getString() throws IOException { return buf.readLine(); }
}
You May Also Find These Documents Helpful
-
exposure from such a large outlay of funds on 90-day notes with no protective covenants.…
- 1121 Words
- 11 Pages
Powerful Essays -
You have now been tasked with providing a recommendation for the project based on the results of a Net Present Value Analysis. Assuming that the required rate of return is 15% and the initial cost of the machine is $3,000,000.…
- 1773 Words
- 8 Pages
Good Essays -
politics and how a person becomes successful at being a politician. The following is a summary of his…
- 1264 Words
- 4 Pages
Better Essays -
The book I will do my assignment on is Pigs in Heaven. Also the character I have chosen is Taylor Greer. Taylor Greer is a protagonist. Taylor Greer’s supporting character is Turtle who helps her make many decisions in life thorough the story. To fully understand Taylor Greer, it’s important to look at her many strengths and weaknesses. Her whole purpose is to make her daughter happy which will be noticed by her daughter later in the story.…
- 638 Words
- 3 Pages
Satisfactory Essays -
In the late 19th century, battle lines of distaste and resentment were drawn between the new immigrant class and the current American citizens. In New York City, the Nativists and the Irish Catholic community clashed on opposing sides of the line. The majority of Irish Catholic immigrants were uneducated, unskilled, and alien to the industrial city life of the new world. Their mass numbers filled up the city’s slums, poor houses, and prisons. With strong aversion from New York Nativists, the Irish immigrant community was initially obstructed from attaining governmental support. This void in representation of such a massive percentage of New York’s population allowed for the emergence and great success of Tammany Hall leaders like George Washington Plunkitt. George Washington Plunkitt, born in 1842, grew up surrounded by this new immigrant Irish-Catholic community. He identified with the city’s immigrant poor and working class; the resented New York Irish were Plunkitt’s community. Although Plunkitt used his political status for his own benefit, his position as a political leader was useful for his community.…
- 782 Words
- 4 Pages
Good Essays -
* How does the story of the potlatch symbolize relations between the Aboriginal and non-Aboriginal people?…
- 364 Words
- 2 Pages
Satisfactory Essays -
A prevalent feature in most ancient Greek tragedy is a character’s downfall due to their fatal flaw, or Achilles’ heel, from the myth of the legendary Greek warrior who was completely indestructible except for his one heel, which of course is where he was shot and killed. When reading Sophocles’ third Theban play, Antigone, most assume the fatal flaw they should focus on is Creon’s hubris, excessive pride and arrogance. But the play is named Antigone, and Antigone is the main character. So what is her fatal flaw? At first glance, Antigone appears to have none, she died defending what she believed was morally and divinely just.…
- 357 Words
- 2 Pages
Good Essays -
To construct drive-through windows at all its locations in order to follow the lead of larger franchise restaurants like McDonald, Burger King and Wendy’s.…
- 521 Words
- 3 Pages
Satisfactory Essays -
When going into this novel, I assumed that it would be a little outdated. It is honestly one of the more modern books that I have read in the past few years, which was surprising. The author gets right into it, telling you about how a plane with school boys was shot down. It had me hooked immediately. His use of actual childlike grammar tripped me up a bit, because sometimes it was hard for you to understand, much like if you were actually listen to a nine year old talk. What got me was how the author had created a boy who was overweight and had thick glasses. He may just be a character, but I honestly felt for him. That’s what I like about the author, he actually makes me have emotions towards the characters. He made me feel pitty for Piggy. He made me dislike Ralph at first for making fun of Piggy.…
- 316 Words
- 2 Pages
Satisfactory Essays -
When Bear is sick, he sacrifices is own needs to meet Bear’s. Also, Crispin is…
- 430 Words
- 2 Pages
Good Essays -
Beaver hind regions secrete goo called castoreum, which the animals use to mark their territory. The U.S. Food and Drug Administration lists castoreum as a “generally regarded as safe” additive, and manufacturers have been using it extensively in perfumes and foods for at least 80 years, according to a 2007 study in the International Journal of Toxicology. “I lift up the animal’s tail,” said Joanne Crawford, a wildlife ecologist at Southern Illinois University, “and I’m like, ‘Get down there, and stick your nose near its bum.’”, “People think I’m nuts,” she added. “I tell them, ‘Oh, but its beavers; it smells really good.’” Castoreum is a chemical compound that mostly comes from a beaver’s castor sacs, which are located between the pelvis and the base of the tail. Because of its close proximity to the anal glands, castoreum is often a combination of castor gland secretions, anal gland secretions, and urine. The fragrant, brown slime is about the consistency of molasses, though not quite as thick, Crawford said. While most anal secretions stink—due to odor-producing bacteria in the gut—this chemical compound is a product of the beaver’s unique diet of leaves and bark, Crawford added. Instead of smelling icky, castoreum has a musky, vanilla scent, which is why food scientists like to incorporate it in recipes.…
- 365 Words
- 2 Pages
Good Essays -
In the Story “Stickeen” by John Muir, he reveals that a man and a dog are not so distinctive from each other. In the beginning Muir comes as this great leader who only has the best intentions for others. He believes that a small and worthless dog will not be able to survive the exploration. However that small and worthless dog proves him wrong and becomes something much more to Muir than just an ordinary dog.…
- 279 Words
- 2 Pages
Good Essays -
If I’m going to tell you about the adventure of my life -- explain how I got to this place with these people, and why I did what I’m going to do next -- I should probably start by explaining a little bit about PipBucks.…
- 968 Words
- 4 Pages
Good Essays -
The movie, Ushpizin, is a Israeli film where it was filmed in the Jerusalem, Israel. This movie is based on one Orthodox Jewish married couple, Moshe and Mali Bellanga who are poor and an infertile couple in the Breslov community in Jerusalem. Without no money to prepare for the upcoming Sukkoth which is one of the joyful Jewish holiday in the fall, they pray much for their financial help. After an agony prayer, they received an unexpected money 1000 dollars that both of them are greatly pleased with this miracle on the eve of the Jewish holiday. They make plans for Sukkah which is a temporary shelter covered in natural materials like a gazebo and used for serving special meals during the Jewish festival of Sukkoth. Meanwhile, the unexpected arrival of two people, Eliahu and Yosef, Moshe is surprised that he thought the Lord has sent him as guests as another miracle. The two friends who escape from the prison, they start staying their house with no longer unwelcome and unacceptance by drinking, smoking, playing loud music. After telling a story in order to get rid of the…
- 508 Words
- 3 Pages
Good Essays -
In compliance with the fulfillment of the requirements on the subject “Business to Business Marketing”, the students of our group would like to present the proposal entitled “Marketing Plan for BANGLA CAT”, in accordance with your instructions.…
- 5318 Words
- 22 Pages
Powerful Essays