H have been on this number for more than a week, please help!

This should be a Pig latin translator.
basically, when a word starts with a vowel, it should translate as ''word''+way.
when the word start with a consonnant, it should give: ''wordWithoutFirstLetter+firstLetterOfWord+ay.
H and Y are consonnants in this respect.

I am almost there, I just have a minor technical error that I need to fix...cannot do it. Please help.

thank you

import java.util.Scanner;

public class PigLatinTranslator
{

public static void main (String[]args)
{

Scanner key=new Scanner(System.in);
//Must figure out how to properly initialize the array.***Figured oct 28 2010 12:26PM
int y=0;
//String vowels[]={"a","A","e","E","i","I","o","O","u","U"};
//String consonants[]={"b","B","c","C","d","D","f","F","g","G","h","H","j","J","k","K","l","L","m","M","n","N","p","P","q","Q","r","R","s","S","t","T","v","V","w","W","x","X","y","Y","z","Z"};
String phrase, word=" ";//We would have to make phrase an array so that we could make it more easily into split up words. The array to be dynamically filled in by the user
String i,temp1,wordCons,t;
int x=0,pos,z=0,j,a=0;
char letter=' ';

System.out.println("Please write some words you would like to translate into Pig-Latin: ");
phrase=key.nextLine()+" ";//I added " " so that the program could also work when the user inputs only one word.


for(x=0;x<phrase.length();x++)//Loop to to go through phrase
//do
{
if(phrase.charAt(x) == ' ')//Looking for the first space
{
word = phrase.substring(0,x);
letter=word.charAt(0);
}
if(letter=='a'||letter=='A'||letter=='e'||letter=='E'||letter=='i'||letter=='I'||letter=='o'||letter=='O'||letter=='u'||letter=='U')
{
System.out.print(word+"-way");
}

else if(letter=='b'||letter=='B'||letter=='c'||letter=='C'||letter=='d'||letter=='D'||letter=='f'||letter=='F'||
letter=='g'||letter=='G'||letter=='h'||letter=='H'||letter=='j'||letter=='J'||
letter=='k'||letter=='K'||letter=='l'||letter=='L'||letter=='m'||letter=='M'||letter=='n'||letter=='n'||letter=='p'
||letter=='P'||letter=='q'||letter=='Q'||letter=='r'||letter=='R'||letter=='s'||letter=='S'||letter=='t'||
letter=='T'||letter=='v'||letter=='V'||letter=='w'||letter=='W'||letter=='x'||letter=='X'||
letter=='y'||letter=='Y'||letter=='z'||letter=='Z')
{


z=(x-1);
t=word.substring(1,z);
System.out.print(t+"-"+letter+"ay");
}

else
{
System.out.print(word);
}

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories