For my code I need to be able to do a pig latin translation for a word but I need help in doing a full phrase including punctuation such as periods
The code I have so far only does one individual word but Im not sure how to include a full phrase
Example
public PigLatinTranslator ()
{
super ("Pig Latin Translator"); // Set the frame's name
frame = getContentPane ();
lblInput = new Label ("Enter a word in English");
lblOutput = new Label ("Translation to Pig Latin");
txtInput = new TextField (50);
txtOutput = new TextField (50);
btnTranslate = new Button ("Translate");
btnClear = new Button ("Clear");
btnCancel = new Button ("Cancel");
frame.setLayout (new GridLayout (4, 2));
btnTranslate.addActionListener (this);
btnClear.addActionListener (this);
btnCancel.addActionListener (this);
frame.add (lblInput);
frame.add (txtInput);
frame.add (lblOutput);
frame.add (txtOutput);
frame.add (btnTranslate);
frame.add (btnClear);
frame.add (btnCancel);
setSize (400, 200); // Set the frame's size
setVisible (true); // Show the frame
setLocation (100, 100);
setDefaultCloseOperation (EXIT_ON_CLOSE);
} // Constructor
public static void main (String[] args)
{
new PigLatinTranslator (); // Create a PigLatinTranslator frame
} // main method
public void actionPerformed (ActionEvent event)
{
if (event.getSource () == btnClear)
{
txtInput.setText ("");
txtOutput.setText ("");
}
if (event.getSource () == btnTranslate)
{
int[] anArray;
String word = txtInput.getText ();
String[] parts = word.split ("\\s+");
for (if
String newWord = "";
if (word.length () <= 1)
{
newWord = word;
}
else
{
char word2;
word2 = word.charAt (0);
if (QUChecker.startsWithQU (word) == true)
{
newWord = word.substring (2);
newWord = newWord + "quay";
}
else if (PigMethods.checkAscii (word2) == true)
{
newWord = word + "way";
}
else
{
String letter = "";
letter = word.substring (0, 1);
newWord = word.substring (1);
newWord = newWord + letter + "ay";
}
}
txtOutput.setText (newWord);
}
else if (event.getSource () == btnCancel)
{
System.exit (0);
}