I am really stuck on this assignment question and the truth is i don't even know how to approach this, meaning which classes to import and what methods to invoke etc... i'm completely new in this Java thing and this is only our second assignment so far
any help on how to approach this would be very much apreciated.
the question:
Pig Latin is a language game primarily used in English which consists of appending syllables to words in order to alter them. There are multiple Pig Latin dialects but for the purposes of this question, the rules are as follows:
* For words that begin with a consonant, move this consonant to the end of the word (separated from the end of the word with "-"), and add "ay". For example, "teacher" would be translated to "eacher-tay".
* For words that begin with a vowel, simply append "-way" to the end of the word. For example, "apple" would be translated to "apple-way".
* Words that start with a non-letter character are not translated.
Write a program that consists of one Java class called PigLatinTranslator, which defines a main() method that asks the user to enter an English sentence. Your program method will then translate this sentence into Pig Latin and display the result.
Additional rules:
* You MUST only move the first consonant in a word to the end of that word; if a word starts with multiple consecutive consonants, you MUST only move the first of these consonants to the end of the word, NOT all of them. For example, "school" would be translated to "chool-say", NOT "ool-schay".
* The letter "h", when occuring at the beginning of a word, MUST always be considered as a consonant, even if it is silent. For example, "honest" would be translated to "onest-hay", NOT "honest-way".
* The letter "y", when occuring at the beginning of a word, MUST always be considered as a consonant. For example, "yellow" would be translated to "ellow-yay", NOT "yellow-way".
* The case of the letters in a word MUST NOT change during translation. That is, an upper-case consonant occuring at the beginning of a word MUST NOT become a lower-case consonant when it is moved to the end of a word. Likewise, a lower-case second letter MUST NOT become an upper-case letter when an upper-case consonant which occurs immediately before it is moved to the end of a word. For example, "September" would translate to "eptember-Say", NOT "Eptember-say".
Notes:
* As specified in the general instructions and regulations for assignment, your program MUST read all the input entered by the user before starting to compute any of the values required by the specification. The easiest way to achieve this for this question is to call the nextLine() method defined in the Scanner class, which reads an entire line of input from the keyboard instead of just one word.
* Your program method MUST be able to properly handle spaces occuring at the beginning or the end of a sentence, as well as multiple spaces occurring between any two consecutive words.
* When constructing the Pig Latin sentence, there MUST be EXACTLY one space between each Pig Latin word. Within a Pig Latin word, there MUST NOT be any spaces between the dash and a group of letters; for example, "teacher" would be translated as "eacher-tay", NOT "eacher - tay".
* The Pig Latin sentence your program constructs MUST start with a Pig Latin word and end with a Pig Latin word; in other words, the Pig Latin sentence MUST NOT start with a space nor end with a space.
* Your program MUST NOT make use of any class defined in the Java Platform API other than Scanner (which you MUST NOT use for anything other than read the input from the keyboard), System (which you MUST NOT use for anything other than display the output), String, StringTokenizer, and Character.
* Your program MUST NOT modify the input variable once it has been assigned. However, you MAY copy the input value and change the copy as many times as you need.

New Topic/Question
Reply




MultiQuote






|