Issue with output for Pig latin program

167 views Asked by At

So im new to coding and i am having some issues... My program is supposed to ask the user for input, and will need to assume that all the input is lowercase... and need to assume there are no extra spaces, and will need to assume it ends with a period. The program will then translate the text into pig latin... Just incase you need the rules for pig latin they are if the word beging with a vowel, add a dash and "way" to the end... Otherwise, add a dash move the first letter to the end, and add "ay"... Now i know my code can be better but i just want to get it running first and then change it if i need too. The issue i am having is that, my code prints all my text but it doesnt not change the individual word to pig latin. And the other text has to also be in pig latin, i have pasted the code below. So any help would be awesome... Thanks.

import java.util.Scanner;
public class PigLat{
   public static void main(String [] args) {

   Scanner scanner = new Scanner(System.in);
   String text, pigLatin;
   char first;

   System.out.print("Enter a line of text: ");
   text= scanner.nextLine();
   first = text.charAt(0);

   if (first == 'a' || first == 'e' || first =='i'||
       first == 'o' || first == 'u')
       pigLatin = text + "-way";

   else
       pigLatin = text.substring(1) + "-" + text.charAt(0) + "ay";

   System.out.println("Input : " + text);
   System.out.print("Output: " + pigLatin);
}
}

My Output:

Enter a line of text: this is a test

Input : this is a test

Output: his is a test-tay ----jGRASP: operation complete.

1

There are 1 answers

0
SexmanTaco On BEST ANSWER

Call every operation on each individual word. Use String[] arr = text.split(" ") and you'll get an array containing all the individual words. Then use a for loop, and do the pig latin stuff on each word. Finally, combine it all back into 1 string, and that's your pig latin string.