Question
Hi I really need help with the methods for this lab for a computer science class. Thanks Main (WordTester - the application) is complete and
Hi I really need help with the methods for this lab for a computer science class. Thanks
Main (WordTester - the application)
-
is complete and only requires uncommenting to test the Word and Words classes as they are completed. The needed imports, class headings, method headings, and block comments are provided for the remaining classes. Javadocs are also provided for the Word and Words classes.
Word
-
The Word class represents a single word. It is immutable. You have been provided a skeleton for this class. Complete the Word class using the block comments, Javadocs, and the following instructions.
1. A String instance variable named word which will contain the word is declared and initialized in the constructor method for you.
2. The one parameter constructor to initialize the word instance variable is also completed.
3. Complete the getLength method to return the number of characters in the word.
4. Complete the getNumVowels method to return the number of vowels in the word. It should use the VOWELS class constant and Strings length, substring, and indexOf methods.
Do not use any String methods that are not in the AP Subset.
5. Complete the getReverse method to return a Word with the letters of this reversed.
6. Complete the toString method to return the String word.
7. Uncomment the Word test code in WordTester and make sure that Word works correctly.
Extra Credit
Word add the following methods to Word:
o public boolean equals(Object other) - This method will compare two Word
objects for equality.
o public Word getSortedUpperCaseWord() - This method will return a new Word with its letters changed to upper case and then sorted. You should create an array of Strings representing the uppercase of each of the letters. Then use either selection sort or insertion sort code to order the array. Then you will have to create a string from the array and then create the Word to return.
Words add the following method to Words:
o public void printAnagrams() - This method will print the pairs of anagrams in this. Two words w1 and w2 are anagrams if
w1.getSortedUpperCaseWord().equals(w2.getSortedUpperCaseWord()) is true. This method should only print each pair once.
/**
* Word.java
* A Word
object represents a word.
*/
public class Word
{
/** The 5 vowels to use for the getNumVowels() method */
private static final String VOWELS = "AEIOUaeiou";
/** The word instance variable */
private String word;
/**
* Constructs a Word
object. No change needed.
* @param w the string used to initialize the word.
*/
public Word(String w)
{
word = w;
}
/**
* Gets the length of the word.
* @return the length (number of characters) of the word.
*/
public int getLength()
{
}
/**
* Gets the first letter of the word.
* @return the fisrt letter of the word
*/
public char getFirstLetter()
{
}
/**
* Gets the last letter of the word.
* @return last letter of the word
*/
public char getLastLetter()
{
}
/**
* Gets a substring of letters from the word.
* @param start the starting index
* @param stop the ending index (inclusive)
* @return the characters from [start, stop] inclusively
*/
public String getLetters(int start, int stop)
{
}
/**
* Finds how many times a letter is in word.
* @param letter to find
* @return count of letter in the word
*/
public int findLetter(char letter)
{
}
/**
* Gives the string representing the word.
* @return the string representing the word.
*/
public String toString()
{
}
/**
* Returns a string that will indicate if word comes before,
* after or is equal to the parameter.
* @param stringCompare the string to compare word to
* @return a string indicating how the two strings compare (before, after, equal)
*/
public String compareToString(String stringToCompare)
{
}
/**
* Gets the reverse word.
* @return the characters of word reversed as a string
*/
public String getReverse()
{
}
/**
* Determines if word is palindrome. Same word forward and backward
* @return true if word is palindrome, false otherwise
*/
public boolean isPalindrome()
{
}
/**
* Gets the number of vowels in the word.
* @return the vowel count in the word
*/
public int getNumVowels()
{
}
}
MAIN
import java.util.Arrays;
public class Main
{
public static void main(String[] args)
{
// Test Word
Word one = new Word("chicken");
System.out.println("Word one: " + one);
System.out.println("Number of chars: " + one.getLength());
System.out.println("Number of vowels: " + one.getNumVowels());
System.out.println("Reverse: " + one.getReverse());
System.out.println(" ")
// Test Words
Words test1 = new Words(new String[] {
"one", "two", "three", "four", "five", "six", "seven",
"alligator"});
System.out.println("Words test1: " + test1);
System.out.println("Number of words with 2 vowels: " +
test1.countWordsWithNumVowels(2));
System.out.println("Number of words with 5 chars: " +
test1.countWordsWithNumChars(5));
test1.removeWordsWithNumChars(3);
System.out.println(" Words test1 after removing words " +
"with 3 chars: " + test1);
System.out.println(" Reversed words: " +
Arrays.toString(test1.getReversedWords()));
System.out.println(" ");
}
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