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.

n this input:

Now is the time,
for all good, and I mean very good men and women,
to visit their grandmothers!

The following output was produced:

ownay isay hetay imetay
orfay allay oodgay anday iay eanmay eryvay oodgay enmay anday omenway
otay isitvay heirtay randmothersgay

THESE WERE GIVEN

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 CODE

import java.lang.*; 
import java.util.*;

public class PigLatin
{
  public String[] phrases;
  public PigLatin(String[] random)
  {
    phrases = random;
  }
  
  public void lowerCase()
  {
    phrases = phrases.toLowerCase(); 
  }
 
  public void punctuationFree()
  {
   phrases = phrases.replaceAll("[^a-z]", ""); 
  }
  
  

  
  public boolean isVowel (char t)
  {
    if (t == 'a' || t == 'e' || t == 'i' || t == 'o' || t == 'u')
      return true;
    else 
      return false;
  }
  

  
  String result;


  public void pigAll() 
  {
    lowerCase();
    punctuationFree();
    StringTokenizer pL = new StringTokenizer(phrases);
 
    while (pL.hasMoreTokens()) 
    {
      String temp = pL.nextTokens();
      char firstLetter = temp.charAt[0];
      if (isVowel(firstLetter) == true)
        temp += "ay";
      else
        temp+= temp.substring(1) + temp.toString() + "ay"; 
      result +=  " " + temp;
    }  
  }
  
  public void pigReport()
  {
      System.out.print(result); 
  }
  
}

"5 errors found:
File: /Users/Draem/Desktop/PigLatin.java [line: 14]
Error: /Users/Draem/Desktop/PigLatin.java:14: cannot find symbol
symbol : method toLowerCase()
location: class java.lang.String[]
File: /Users/Draem/Desktop/PigLatin.java [line: 19]
Error: /Users/Draem/Desktop/PigLatin.java:19: cannot find symbol
symbol : method replaceAll(java.lang.String,java.lang.String)
location: class java.lang.String[]
File: /Users/Draem/Desktop/PigLatin.java [line: 42]
Error: /Users/Draem/Desktop/PigLatin.java:42: cannot find symbol
symbol : constructor StringTokenizer(java.lang.String[])
location: class java.util.StringTokenizer
File: /Users/Draem/Desktop/PigLatin.java [line: 46]
Error: /Users/Draem/Desktop/PigLatin.java:46: cannot find symbol
symbol : method nextTokens()
location: class java.util.StringTokenizer
File: /Users/Draem/Desktop/PigLatin.java [line: 47]
Error: /Users/Draem/Desktop/PigLatin.java:47: cannot find symbol
symbol : variable charAt
location: class java.lang.String"

I assume that constructor at the beginning is wrong, and also the import statement.

THANKS YOUR TIME OR TIPS

~Ken

Read the stack trace. Where it says "cannot find symbol", it means you're referring to a method or a variable that doesn't exist.

For example, on line 14 - can't find any method called "toLowerCase" in String

String has a method by that name, but phrases[] isn't a String, it's an array of Strings. You'll have to walk the array and apply the method for each item. replaceAll() isn't a method of String - check the API. Go through the other items, the compiler is telling you exactly what the problems are.

Go on through each of those items the same way - you've been a bit sloppy in referring to methods. Check the API for the correct calls.

thanks for the tips
here is the revised one, but something was still wrong.
I was able to run the program, but whatever I entered into the box, nothing happen.
more hint?

import java.lang.*; 
import java.util.*;

public class PigLatin
{
  public String[] phrases;
  public PigLatin(String[] random)
  {
    phrases = random;
  }
  
  public void lowerCase()
  {
    for (int j = 0; j < phrases.length; j++)
      phrases[j] = phrases[j].toLowerCase(); 
  }
 
  public void punctuationFree()
  {
    for (int j = 0; j < phrases.length; j++)
      phrases[j] = phrases[j].replaceAll("[^a-z]", ""); 
  }
  
  

  
  public boolean isVowel (char t)
  {
    if (t == 'a' || t == 'e' || t == 'i' || t == 'o' || t == 'u')
      return true;
    else 
      return false;
  }
  

  
  String result;


  public void pigAll() 
  {
    lowerCase();
    punctuationFree();
    StringTokenizer pL = new StringTokenizer(phrases.toString());
 
    while (pL.hasMoreTokens()) 
    {
      String temp = pL.nextToken();
      char firstLetter = temp.charAt(0);
      if (isVowel(firstLetter) == true)
        temp += "ay";
      else
        temp+= temp.substring(1) + temp.toString() + "ay"; 
      result +=  " " + temp;
    }  
  }
  
  public void pigReport()
  {
      System.out.println(result); 
  }
  
  
  
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.