You will write a Java class
WordProcessor. Inside this class you will
define a method called
isPalindrome
which takes as an argument a String and returns a boolean variable
that indicates whether the string is a palindrome or not. Recall that a
palindrome is a word that has the property of reading the same in
either direction (an example is the word 'anna'). You will also define
a method
getReverse which
takes a String as an argument and returns a new String with
value equal to the reverse of the argument. The signatures of the two
methods are the following:
public static boolean isPalindrome(String aString)
public static String getReverse(String aString)
Both methods will first convert the String to an array of characters
(char[]). You can get a char[] that contains the characters of a
String by calling the
toCharArray() of the String class. For example, you
can convert the contents of a String str into a char[] with the following
statement:
String str = "anna";
char[] strchars = str.toCharArray();
// Now, strchars[0] == 'a', strchars[1] == 'n', ...
The main method of your program should first ask the user to provide
an integer to define the length of an array of strings. After defining
this array, your program will then ask the user to input words to fill
in the array. Then, for each of the elements of the array, it should
call both
isPalindrome and
getReverse and print some
messages containing their return values. A possible output for the
program would be the following:
Please, input an array length: 2
Please, insert string 1: hello
Please, insert string 2: anna
hello is not a palindrome
Reverse of hello is: olleh
anna is a palindrome
Reverse of anna is: anna
Here is a template for WordProcessor.java.
import java.util.*;
/**
* @author name 1: discussion section time:
* @CS account user name:
*
* @author name 2: discussion section time:
* @CS account user name:
*
* @version Date
*
*/
Your program should be internally correct (sound logic) and
externally correct (following
Java style
guideline).