So I have this very simple program, it is designed to be a simple text editor. You type in a text, and you have a few options, including add words and replace words etc.. the one thing that i cannot get to work is if you type "pal", the program will say back if its a palindrome or not. i took out the rest of the program to pretty up my post. my two problems are where "pal" method is executed is incorrect, and the character.isletter statements but here is what i have:
package Assignment6;
import java.util.Scanner;
public class part2 {
public static void main(String[] args) {
System.out.print("Enter the text to be edited: ");
Scanner console = new Scanner(System.in); //Creates console scanner
String text = console.nextLine(); // input string Text (initial text)
System.out.print("Edit: ");
String command = console.nextLine(); // Command string input
String function = command.substring(0,3).toLowerCase(); //takes first three letters and makes "function"
String pars = command.substring(3).trim(); //creates "pars" as the rest of the string, this is the parameters
//works up to insert
while (!function.equals("sto")){ //creates while and creates stop point (sto)
if (function.equals("ins")){ //if it equals insert
text = insert(text, pars); // use text to insert parameters goes to INSERT METHOD
System.out.println("The changed text is: " + text);} //prints the updated text
else if (function.equals("rep")){ //if it equals replace
text = replaceFirst(text,pars);
System.out.println("The changed text is: " + text);
}
else if (function.equals("del")) {
text = delete(text, pars);
System.out.println("The changed text is: " + text);
} else if (function.equals("pal")){
text = palindrome(String text);
}
else {
System.out.println("The function " + function + " is not defined. Original text is not changed.");
System.out.println("The unchanged text is: " + text);
}
System.out.print("Edit: ");
command = console.nextLine();
function = command.substring(0,3).toLowerCase();
pars = command.substring(3).trim();
}
System.out.println("Program stopped");
}
public static void palindrome(String text){
int left, right;
char charLeft, charRight;
text.toLowerCase();
{
left = 0;
right = text.length() - 1;
while (left < right){
charLeft = text.charAt(left);
charRight = text.charAt(right);
if (charLeft == charRight){
left++;
right--;}
if Character.isLetter(charLeft){
left++;}
if Character.isLetter(charRight){
right--;}
else break;
}
System.out.println();
if (left < right)
System.out.println ("This text is not a palindrome: " + text);
else
System.out.println ("This text is a palindrome: " + text);
return;
}
}
}