Question: Hi I am almost done with this lab with for my class but I keep getting an error message when I try and call the

Hi I am almost done with this lab with for my class but I keep getting an error message when I try and call the getReverse method on the getPalindrome method. Any help would really be appreciated.

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.

/**

* 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;

}

public String getReverse()

{

String reverse = "";

for (int i = word.length() - 1; i >= 0; i--)

{

reverse += word.substring(i, i + 1);

}

return reverse;

}

/**

* Determines if word is palindrome. Same word forward and backward

* @return true if word is palindrome, false otherwise

*/

public boolean isPalindrome()

{

boolean palindrome = true;

if(word.getReverse().equals(word)){

palindrome = true;

}

else{

palindrome = false;

}

return palindrome;

}

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(" ");

}

exit status 1 Word.java:133: error: cannot find symbol if (word.getReverse().equals(word)) { symbol: method getReverse(). location: variable word of type String Words.java:117: error: incompatible types: String cannot be converted to Word Word currentObj = words.get(i).getReverse(); 2 errors

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!