Develop an application that accepts one word from the user as input. The application should then translate and output the word in a secret language according to the following rules: The first letter of the word is placed at the end and the letters ‘ay’ are added to the end.
The application should make use of instantiable classes.
myCODE(Instantiable class):
public class PigLatin{ private String word; private String newWord; private StringBuffer strBuff; public PigLatin(){ word = " "; newWord = " "; strBuff = new StringBuffer(); } public void setWord(String word){ this.word = word; } public void compute(){ for(int i = 1; i < word.length(); i = i +1){ strBuff.append(word.charAt(i)); } strBuff.append(word.charAt(0)); strBuff.append("ay"); newWord = strBuff.toString(); } public String getNewWord(){ return newWord; } } [QUOTE]AppClass:[/QUOTE] import javax.swing.JOptionPane; public class PigLatinApp{ public static void main(String args[]){ String word, newWord; PigLatin myPigLatin = new PigLatin(); word = JOptionPane.showInputDialog(null,"Enter a word"); myPigLatin.setWord(word); myPigLatin.compute(); newWord = myPigLatin.getNewWord(); JOptionPane.showMessageDialog(null, "That translates to "+newWord); } }
There's no problem to this code as it functions properly.
For example, Hello becomes elloHay.
However, I have difficulties modifying this code so that it allows the user to translate a sentence made up of many words separated by spaces.
For example, Hello world becomes elloHay orldway.
I think I'll have to store newWord into an array and then loop through that array to print it back out. How do I store this newWord variable into an array??