, Oh!-->Ohway!, "hello"-->"ellohay", "hello!"-->"ellohay!". So basically i have to modify my program to handle punctuation. I have worked a lot on this one, could anyone please tell me how to modify it so it can handle punctuation?
I don't have much time until i need this done , so the sooner the better.Thank you all.
import java.util.Scanner;
public class PigLatin {
public static void main(String[] args)
{
String str;//the string that will hold the value of the word entered by the user
Scanner scanner = new Scanner(System.in);//this creates a new scanner to register input
char s;//the first character of the string
char m;
System.out.println("Enter a word: ");//prompts user to enter a word
str = scanner.next();//assigns the string
int l = str.length();//determines the length of the string
String endString;
String startString;
String finalString;//the final output
String mtr;
String lowercase;//the entered string all converted to lowercase
for(int k =0;k<l;k++)//checks all letters in order to see which is a vowel
{
s = str.charAt(k);
if(k==0)//if the first letter is a vowel than it will just append "way"
{
if(Character.isUpperCase(s))//prints out the result in Capital first letter if the input string is in capital
{
str = str.toLowerCase();
for(int v = 0;v<=l;v++)
{
int b = str.charAt(v);
if(v==0)//if the first letter is a vowel than it will just append "way"
{
if(b=='a'||b=='e'||b=='i'||b=='o'||b=='u'||b=='A'||b=='E'||b=='I'||b=='O'||b=='U')
{
finalString = str + "way";
System.out.println(finalString.substring(0,1).toUpperCase() + finalString.substring(1));//prints out the result in Capital first letter
break;
}
else if(b=='y'||b=='Y')//this makes y count as a consonant
{
mtr = str.substring(1,l);//makes the string not include y
int p = mtr.length();
for(int n = 0;n<p;n++)//checks all the letters in the new string for a vowel and basically uses the basic rules
{
m = mtr.charAt(n);
if(m == 'q'|| m=='Q')//if the first vowel is a "u" and the letter before it is a "q"
{
if(mtr.charAt(n+1)=='u')
{
endString = mtr.substring(0,n+2);//makes the endString also include u
endString = endString + "ay";
startString = mtr.substring(n+2,p);
finalString = startString +"y"+ endString;
System.out.println(finalString.substring(0,1).toUpperCase() + finalString.substring(1));
break;
}
}
if(m=='a'||m=='e'||m=='i'||m=='o'||m=='u'||m=='A'||m=='E'||m=='I'||m=='O'||m=='U')//if its a vowel or "y" than executes commands below
{
endString = mtr.substring(0, n);//gets the letters before the vowel
endString = endString + "ay";
startString = mtr.substring(n,p);//gets the letters after the vowel
finalString = startString +"y"+ endString;
System.out.println(finalString.substring(0,1).toUpperCase() + finalString.substring(1));//prints the final result which is the combination of startString with endString
break;//stops code after doing the above
}
else if(n==p-1)//if its the end of the word
{
System.out.println("ERROR");
break;
}
}
break;
}
}
{
if(b == 'q'|| b=='Q')//if the first vowel is a "u" and the letter before it is a "q"
{
if(str.charAt(v+1)=='u')
{
endString = str.substring(0,v+2);//makes the endString also include u
endString = endString +"ay";
startString = str.substring(v+2,l);
finalString = startString + endString;
System.out.println(finalString.substring(0,1).toUpperCase() + finalString.substring(1));
break;
}
}
if(b=='a'||b=='e'||b=='i'||b=='o'||b=='u'||b=='A'||b=='E'||b=='I'||b=='O'||b=='U'||b=='y'||b=='Y')//if its a vowel or "y" than executes commands below
{
endString = str.substring(0, v);//gets the letters before the vowel
endString = endString + "ay";
startString = str.substring(v,l);//gets the letters after the vowel
finalString = startString + endString;
System.out.println(finalString.substring(0,1).toUpperCase() + finalString.substring(1));//prints the final result which is the combination of startString with endString
break;//stops code after doing the above
}
else if(v==l-1)//if its the end of the word
{
System.out.println("ERROR");
break;
}
}
}
break;
}/////////////////////
if(s=='a'||s=='e'||s=='i'||s=='o'||s=='u'||s=='A'||s=='E'||s=='I'||s=='O'||s=='U')
{
finalString = str + "way";
System.out.println(finalString);
break;
}
else if(s=='y'||s=='Y')//this makes y count as a consonant
{
mtr = str.substring(1,l);//makes the string not include y
int p = mtr.length();
for(int n = 0;n<p;n++)//checks all the letters in the new string for a vowel and basically uses the basic rules
{
m = mtr.charAt(n);
if(m == 'q'|| m=='Q')//if the first vowel is a "u" and the letter before it is a "q"
{
if(mtr.charAt(n+1)=='u')
{
endString = mtr.substring(0,n+2);//makes the endString also include u
endString = endString + "ay";
startString = mtr.substring(n+2,p);
finalString = startString +"y"+ endString;
System.out.println(finalString);
break;
}
}
if(m=='a'||m=='e'||m=='i'||m=='o'||m=='u'||m=='A'||m=='E'||m=='I'||m=='O'||m=='U')//if its a vowel or "y" than executes commands below
{
endString = mtr.substring(0, n);//gets the letters before the vowel
endString = endString + "ay";
startString = mtr.substring(n,p);//gets the letters after the vowel
finalString = startString +"y"+ endString;
System.out.println(finalString);//prints the final result which is the combination of startString with endString
break;//stops code after doing the above
}
else if(n==p-1)//if its the end of the word
{
System.out.println("ERROR");
break;
}
}
break;
}
}
{
if(s == 'q'|| s=='Q')//if the first vowel is a "u" and the letter before it is a "q"
{
if(str.charAt(k+1)=='u')
{
endString = str.substring(0,k+2);//makes the endString also include u
endString = endString +"ay";
startString = str.substring(k+2,l);
finalString = startString + endString;
System.out.println(finalString);
break;
}
}
if(s=='a'||s=='e'||s=='i'||s=='o'||s=='u'||s=='A'||s=='E'||s=='I'||s=='O'||s=='U'||s=='y'||s=='Y')//if its a vowel or "y" than executes commands below
{
endString = str.substring(0, k);//gets the letters before the vowel
endString = endString + "ay";
startString = str.substring(k,l);//gets the letters after the vowel
finalString = startString + endString;
System.out.println(finalString);//prints the final result which is the combination of startString with endString
break;//stops code after doing the above
}
else if(k==l-1)//if its the end of the word
{
System.out.println("ERROR");
}
}
}
}
}

New Topic/Question
Reply



MultiQuote



|