4 Replies - 4652 Views - Last Post: 04 March 2012 - 11:40 PM Rate Topic: -----

#1 stinson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-February 12

Converting words to pig latin

Posted 04 March 2012 - 11:25 PM

So the problem is: "Pig Latin" is a fake language used as a children's game. A word in English is "translated" into Pig Latin using the following rules:

If the English word begins with a consonant, move the consonant to the end of the word and add "ay". The letter Y should be considered a consonant.
If the English word begins with a vowel (A, E, I, O, or U), simply add "way" to the end of the word.
(This is a simplified dialect of Pig Latin, of course.)

Ask the user for a word (one string) and output its Pig Latin translation (one string). You may assume that the input does not contain digits, punctuation, or spaces. The input may be in any combination of uppercase or lowercase. The case of your output does not matter. Use IO.outputStringAnswer() to output.

so far my code is :



public class PigLatin {
	public static void main(String[] args)
    {
             
            System.out.println("Please enter a phrase that you want me to translate into Pig Latin: ");
            String prepig = IO.readString();
            char prepig1 = Character.toLowerCase(prepig.charAt(0));
            if (prepig1 == "a" || prepig1 == "e" || prepig1 == "i" || prepig1 == "o" || prepig1 == "u")
            {
                   String finalstr = prepig + "way";
                   System.out.println(finalstr);
            }
            else
            {
                    String first = prepig.substring(0,1);
                    String slice = prepig.substring(1,prepig.length());
                    System.out.println(slice + first + "ay");
            }
 
             
    }

}



However in eclipse, this line
 if (prepig1 == "a" || prepig1 == "e" || prepig1 == "i" || prepig1 == "o" || prepig1 == "u") 

is in red and it says "Incompatible operand types char and String"
What does this mean and how can I fix it?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Converting words to pig latin

#2 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Converting words to pig latin

Posted 04 March 2012 - 11:29 PM

Chars need to be in single quotes, "u" is a string, 'u' is a char.

Something tells you you might run into some more problems than that though.

This post has been edited by Tarkenfire: 04 March 2012 - 11:29 PM

Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7292
  • View blog
  • Posts: 12,103
  • Joined: 19-March 11

Re: Converting words to pig latin

Posted 04 March 2012 - 11:30 PM

Double quotes (") indicate a String - an immutable object which consists of an array of characters and a lot of methods for returning permutations of itself and information about itself.

Single quotes (') indicate a char - a primitive type consisting of a Unicode code point.

Replace the double quotes with single quotes, that should do the trick.
Was This Post Helpful? 1
  • +
  • -

#4 stinson  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 21-February 12

Re: Converting words to pig latin

Posted 04 March 2012 - 11:30 PM

View PostTarkenfire, on 04 March 2012 - 11:29 PM, said:

Chars need to be in single quotes, "u" is a string, 'u' is a char.

Something tells you you might run into some more problems than that though.


Oh wow thanks for that. This is my first time working with string/character so I'm still not sure what I'm doing.

Why do you say that I'll have more problems than that? Just curious..like I said I'm new at this and don't know what to do haha
Was This Post Helpful? 0
  • +
  • -

#5 Tarkenfire  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 115
  • View blog
  • Posts: 314
  • Joined: 04-May 11

Re: Converting words to pig latin

Posted 04 March 2012 - 11:40 PM

Unless you're omitting a second class for handling IO called IO, then this line seems...off to me:

String prepig = IO.readString();


If it is your own class, then just ignore me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1