the assignment is on
http://cs.ahsweb.org/text/LessonA10/Lab-...
Below is what I wrote. It doesn't work. please help to correct if you can.
package StringLab;
public class StringUtil {
public static String reverse(String str) {
if (str.length() == 1)
str.charAt(1);
return reverse(str.substring(1) + str.charAt(0));
}
public static boolean palindrome(String str) {
String str2;
str2 = str.replaceAll("[^A-Za-z ]", "");
str2 = str.replaceAll(" ", "");
str2 = reverse(str);
if (str.equalsIgnoreCase(str2))
return true;
else
return false;
}
public static String pigLatin(String sentence) {
String latinWord = "";
String firstLetter = "";
firstLetter = sentence.substring(0,1);
if ((firstLetter.matches("[aeiou]")) || (firstLetter.matches("[AEIOU]")))
{
latinWord = sentence + "way ";
}
else
{
latinWord = sentence.substring(1) + sentence.substring(0,1) + "ay ";
}
return(latinWord);
}
public static String shorthand(String str) {
str = str.replaceAll("and", "&");
str = str.replaceAll("are", "R");
str = str.replaceAll("for", "4");
str = str.replaceAll("to", "2");
str = str.replaceAll("you", "U");
str = str.replaceAll("a", "");
str = str.replaceAll("e", "");
str = str.replaceAll("i", "");
str = str.replaceAll("o", "");
str = str.replaceAll("u", "");
str = str.replaceAll("A", "");
str = str.replaceAll("E", "");
str = str.replaceAll("I", "");
str = str.replaceAll("O", "");
str = str.replaceAll("U", "");
return str;
}
}
--------------
package StringLab;
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
String sentence;
Scanner scan = new Scanner(System.in);
System.out.print("Enter a English sentence: ");
sentence = scan.nextLine();
StringUtil su = new StringUtil();
su.palindrome(sentence);
su.pigLatin(sentence);
su.shorthand(sentence);
}
}