Question: The WordCruncher class Write the Java code for the class WordCruncher. Include the following members: A default constructor that sets the instance variable 'word' to
The WordCruncher class Write the Java code for the class WordCruncher. Include the following members:
A default constructor that sets the instance variable 'word' to the string "default".
A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make your work on some of the following methods much easier.)
A method String toString() that returns the instance variable.
A method int numLetters() that returns the number of letters in the instance variable.
A method int numVowels() that returns the number of vowels in the instance variable.
A method boolean beginsWithVowel() that returns true if the first letter of the instance variable is a vowel, and false otherwise.
A method String toPigLatin() that returns a String containing the 'pig latin' version of the instance variable. The rules for translating a word to pig latin are: If the word begins with a consonant, take the first letter of the word and move it to the end of the word, followed by 'ay' If the word begins with a vowel, add 'way' to the word. Hint: the method beginsWithVowel() makes this easier. For example, PIG LATIN IS FUN becomes IGPAY ATINLAY ISWAY UNFAY in pig latin. Note that despite the last example, our toPigLatin() method operates on words, not on complete sentences.
A method String toGibberish() that returns a String containing the 'gibberish' version of the instance variable. The rules for translating a word into gibberish are: If the word begins with a consonant, follow the first letter with 'ithag'. So the word 'big' would translate to 'bithagig'. If the word begins with a vowel, place 'ithag' at the front. So the word 'is' becomes 'ithagis'.
A method String reverse() that returns a String that contains the characters of the instance variable, but in reverse.
A method int numCharOccurrences(char ch) that returns a count of the number of times the parameter char ch occurs in the instance variable. A character that is a match except for the case (uppercase instead of lowercase or vice versa) should be counted as an occurrence.
The application
Write a class named WordCruncherTest that has only a main method that:
asks the user for a word with the option to enter the word "quit" to quit creates a WordCruncher object that contains this word (unless the word is "quit") and then:
outputs the number of letters in this object outputs the number of vowels in this object output the object string in reverse outputs the pig latin translation of the string stored in the object outputs the gibberish translation of the string stored in the object asks the user to enter one letter, and returns a message indicating how many occurrances of that letter are in the word The program should continue to do this until the user enters the word "quit"
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
