****Hi everyone! I have to make a pig latin translator for cs hwk. I've made my code and everything works up until i put it together. I need to debug it, but can't figure out the if statement in the main.
The assignment is
"Here's how to translate the English word englishWord into the Pig Latin word pigLatinWord:

If there are no vowels in englishWord, then pigLatinWord is just englishWord + "ay". (There are ten vowels: 'a', 'e', 'i', 'o', and 'u', and their uppercase counterparts.)

Else, if englishWord begins with a vowel, then pigLatinWord is just englishWord + "yay".

Otherwise (if englishWord has a vowel in it and yet doesn't start with a vowel), then pigLatinWord is end + start + "ay", where end and start are defined as follows:

Let start be all of englishWord up to (but not including) its first vowel.
Let end be all of englishWord from its first vowel on."****

I basically prompt the user over and over until they quit.
my code is as follows

public class pig_Latin
{
    public static void main (String [] args)
    {
        String englishWord;

        //char Vowel = i || o || e || u || y;

        System.out.println("I can translate English words into Pig Latin. Please type a word and then press <Enter>. ");
        char letter;
        int vowelSpace;
        char vowel;
        ConsoleIO input = new ConsoleIO();
        do 
        {

            englishWord = input.readToken();
            letter = englishWord.charAt(0);
            vowelSpace = englishWord.indexOf('e');
            if (vowelSpace>0)
            {
                vowel = englishWord.charAt(vowelSpace);

                if ( letter != 'i' || letter != 'o' || letter != 'e' || letter != 'u' || letter != 'a' || letter != 'I' || letter != 'O' || letter != 'E' || letter != 'U' || letter != 'Y'|| letter != 'A')
                    System.out.println(addYAY(englishWord));

                else if ( letter == 'i' || letter == 'o' || letter == 'e' || letter == 'u' ||  letter == 'a' || letter == 'I' || letter == 'O' || letter == 'E' || letter == 'U' || letter == 'A'&& (vowel != 'i' || vowel != 'o' || vowel != 'e' || vowel != 'u' ||  vowel != 'a' || vowel != 'I' || vowel != 'O' || vowel != 'E' || vowel != 'U' || vowel != 'A' && vowelSpace <0))
                    System.out.println(addAY(englishWord));
                else if (letter != 'i' || letter != 'o' || letter != 'e' || letter != 'u' ||  letter != 'a' || letter != 'I' || letter != 'O' || letter != 'E' || letter != 'U' ||  letter != 'A' && (vowel == 'i' || vowel == 'o' || vowel == 'e' || vowel == 'u' ||  vowel == 'a' || vowel == 'I' || vowel == 'O' || vowel == 'E' || vowel == 'U' || vowel == 'A') && vowelSpace>0)
                    System.out.println(changeWord(englishWord));
            }

            System.out.println("Would you like to translate another word?");
            String answer = input.readToken();

            if (answer.equals("Yes") || answer.equals("yes"))
            {
                System.out.println("Please enter new word");
            }
            else 
                break;

        }while (englishWord.compareTo("No") != 0);
        /*string AddAY(string EnglishWord){
        return englishWord + 
         * 
         */

    }

    //private static pigLatinTest(String englishWord)
    private static String changeWord (String englishWord)
    {
        //char vowel = ;
        int vowelSpace = englishWord.indexOf('e');
        int vowelSpace2 = vowelSpace -1;

        int letterCount = englishWord.length();
        return englishWord.substring(vowelSpace, letterCount) + englishWord.substring( 0 , vowelSpace) + "ay" ;

    }
    private static String addYAY (String englishWord) //starts w/ vowel
    {
        return englishWord + "yay";

    }

    private static String addAY (String englishWord)
    {
        return englishWord + "ay";
    }

    // String add
}
if ( letter != 'i' || letter != 'o' ...

There's a problem.
If the letter is 'i' then letter != 'o' is true
If the letter is 'o' then letter != 'i' is true
If the letter is anything else then both are true.
You OR them together, so the result is always true for all possible values of letter

I'm not exactly sure how I'd change that, it still works on it's own.
Is there any other operator i can use?

You probably wanted to AND those conditions together to see if the letter was not a vowel - just take a couple of examples and run them through it in your head or on paper to see how it works.

Alternatively, since you ask, the String class has a useful contains method that tells you if the string contains a specified substring. eg "ABC".contains("A") returns true, but "ABC".contains("D") returns false. ;)

Edited 3 Years Ago by JamesCherrill

This question has already been answered. Start a new discussion instead.