0

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);
}

}

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Ezzaral
0

> please help to correct if you can.
Why?

Could it be because you posted on the wrong forum? There is a forum just for Java you know
Or could it be because you ignored ALL the information about code tags.

See your other post as well.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.