So here are the assignment instructions:
For this assignment, your job is to create a program that reads in multiple lines of text, and then produces the translation of that text into the English language variant known as "pig latin".
Pig latin works this way: if a word begins with a vowel (a-e-i-o-u), then "ay" is added to the end of the word (so "idle" -> "idleay", and "often" -> "oftenay"); on the other hand, if a word begins with a consonant, then the first letter is removed, and is placed at the end of the word, followed by "ay" (so "month" -> "onthmay", and "castle" -> "astlecay").
Your program, then, should read in multiple lines of text, ending finally with two carriage returns. After the reading segment ends, your program should then print the pig latin translation of the input text. As a simplification, report the translation with no punctuation, and in all lower case.
Below we give you the driver (the PigLatinTester class), and an input class called JInputer, which uses JOptionPane for input. Your job is to write the PigLatin class so that PigLatinTester works appropriately.
public class PigLatinTester{ public static void main(String[] args){ JInputer r = new JInputer("pig latin!"); r.multiInputs(); r.reportPhrases(); PigLatin p = new PigLatin(r.getPhrases()); p.pigAll(); p.pigReport(); } }
import javax.swing.JOptionPane; public class JInputer{ private String cur = ""; private String message; //JOptionPane caption private String[] phrases = new String[50]; private int pos = 0; public JInputer(String msg){ message = msg; } public JInputer(){ } public String getInput(){ cur = JOptionPane.showInputDialog(message); phrases[pos] = cur; pos++; return cur; } public void multiInputs(){ String s = " "; while (s.length() > 0){ s = getInput(); } } public String[] getPhrases(){return phrases;} public void reportPhrases(){ for (String s : phrases) if (s != null) System.out.println(s); } }
My job is to write the PigLatin class so the driver works and this is what i got so far but it has compilation issues...
and i get these compilation errors:import java.lang.*; public class PigLatin{ public String[] phrases; public String result; public String t; public PigLatin(){} public String pigAll(){ result=""; StringTokenizer str; str = new StringTokenizer(phrases,"\t\n\r\f,.?!;: "); while(str.hasMoreTokens()){ result += " "; result += translateTo(str.nextToken()); } return result; } public String translateTo(String s){ String s2 = ""; for(int j=0; j< phrases.length; j++){ s=phrases[j]; s=s.toLowerCase(); if((s.charAt(0)=='a' || s.charAt(0)=='e' || s.charAt(0)=='i' || s.charAt(0)=='o' || s.charAt(0)=='u')){ s2 = (s+"ay"); } else{ s2 = s.substring(1) + "ay"; } } return s2; } public void pigReport(){ System.out.println(pigAll()); } }
File: C:\Users\Korobkov\PigLatin.java [line: 16]
Error: C:\Users\Korobkov\PigLatin.java:16: cannot find symbol
symbol : constructor StringTokenizer(java.lang.String[],java.lang.String)
location: class java.util.StringTokenizer
File: C:\Users\Korobkov\PigLatinTester.java [line: 10]
Error: C:\Users\Korobkov\PigLatinTester.java:10: cannot find symbol
symbol : constructor PigLatin(java.lang.String[])
location: class PigLatin
What is the matter with the constructor and why is the
StringTokenizer not being recognized...