Writing a Pig Latin Translator

PigDriver class and a PigLatin class

Page 1 of 1

1 Replies - 4982 Views - Last Post: 05 April 2010 - 05:19 AM Rate Topic: -----

#1 defoLinY  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-April 10

Writing a Pig Latin Translator

Posted 04 April 2010 - 08:30 PM

Hey guys I was looking at this thread (http://www.dreamincode.net/forums/topic/19475-help-writing-a-pig-latin-translator/) and it I saw that the code there was all within one class. I am wondering how I can write this program with two classes, a PigDriver class and a PigLatin class ...

Here's the question, THANKS FOR ANY HELP!


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 PigDriver class). Your job is to write the Piglatin class so that PigDriver works appropriately.

import java.util.*;
public class PigDriver{
  public static void main(String[] args){
   Scanner scan = new Scanner(System.in);
   String t = " ";
   Piglatin p = new Piglatin();
   while(t.length() > 0){
     t = scan.nextLine();
     t = t.toLowerCase();

On 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

Some requirements, and tips:
* make sure you comment all of your methods with one line that tells what that method does
* Additional helper methods a surely useful; my solution has four methods.
* You will need to use StringTokenizer in the Piglatin class

Is This A Good Question/Topic? 0
  • +

Replies To: Writing a Pig Latin Translator

#2 ashrack  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 32
  • Joined: 04-April 10

Re: Writing a Pig Latin Translator

Posted 05 April 2010 - 05:19 AM

first create an empty constructor in Piglatin class named

public Piglatin() {...} 

then create 2 methods and fill them with the required code. If you want them to return a value just replace 'void' with the type of value you wish to return.:
public void pigConvert(String t) {...}
public void pigReport() {...}

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1