In order to not overwhelm the message boards, I hope this is OK. I have created one thread where I can post questions I have about my Java HW.
So first of all I am new here! Thank you for having a forum like this. Very helpful. A little about me: Undergrad student, interested in pursuing Computer Science, and currently taking a Java class with sometimes very difficult homework. I am not simply looking for answers here, but help UNDERSTANDING what I am doing.
So here is a question on my recent HW:
Write your program in the file PigLatin.java.
"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). Do not make any assumptions about the case (uppercase/lowercase) of the input. However, it does not matter whether your output is in uppercase or lowercase.
Construct a set of test cases for your program, and enter these in assign4-testcases.txt.
This is the code I have written so far:
My problem is that for test cases where I am using a word that begins with a vowel, I am not getting the correct output. For example:
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();
String prepig1 = prepig.substring(0,1);
boolean tester = (prepig1 == "a" || prepig1 == "e" || prepig1 == "i" || prepig1 == "o" || prepig1 == "u" || prepig1 == "A" || prepig1 == "E" || prepig1 == "I" || prepig1 == "O" || prepig1 == "U");
String finalstr = prepig + "way";
String first = prepig.substring(0,1);
String slice = prepig.substring(1,prepig.length());
System.out.println(slice + first + "ay");
If I input the string "Octagon" my output is "ctagonoay"
What am I doing wrong?
Thanks for any help!