Question:
help with java piglatin program please.?
BadGirl_02
2010-04-05 15:49:57 UTC
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 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();

p.pigConvert(t);

}

p.pigReport();

}

}
Three answers:
Beau
2010-04-05 17:03:00 UTC
I wont write this for you but ill give you some hints on how to write this class:



1. Before anything else, its obvious that this class will need a string to hold all of the translated data.



public class Piglatin {

private String outputPiglatin;

//Method bodies etc...

}



2. pigConvert() needs to take a string as a parameter, and since the result isn't stored in a variable the methods type can be void. Your method heading for the pigConvert() should look like this :



public void pigConvert(String inputString) {

//Your code here

}



3. Inside pigConvert you will need to write a few things:

a. Split inputString into seperate words like so:

String words[] = inputString.split(" ");

b. a for loop which goes through all the words in "words", looking for vowels and placing ay at the end of the words with vowels. The words without vowels will just need to have the letter put at the end of the original word without its first letter and then 'ay' is added:



this.outputPiglatin = "";



for(int i=0; i
{

switch(words[i].charAt(0)) {

case 'a':

case 'e':

case 'i':

case 'o':

case 'u':

words[i] = words[i] + "ay";

this.outputPiglatin = this.outputPiglatin + words[i] + " ";

break;

default:

words[i] = words[i].substring(1) + words[i].charAt(0) + "ay";

this.outputPiglatin = this.outputPiglatin + words[i] + " ";

break;

}

}



4. Now for pigReport(). Since this takes no parameters and doesnt have its result stored in any variable in the pigDriver class, it can also be void. This method only will have to print out the string to the user:



public void pigReport() {

System.out.println(outputPiglatin);

}



That's a rough code outline and it'll probably take you about 20 minutes to write this.
vickie
2016-04-30 01:36:34 UTC
If you have a problem to helping your child that has problem reading, no matter what age she\he the program is things you need, Children Learning Reading from here https://tr.im/mFcrw .

Children Learning Reading is distinctive from other programs because it doesn't depend on training phrases by sight, a method that utilizes kiddies realizing and memorizing words by their content and structure. You might have seen (or also bought!) classes that promote full word acceptance learning, these programs usually need you to sit your youngster before a television or pc check for an important period of time so as in order for them to understand words that will allow them to begin their examining journey.

With Children Learning Reading your kid may only need to invest 5\15 minutes at time and he\she may learn to build the term creating the complete process of learning how to read a lot more effectively.
2016-02-26 00:16:29 UTC
orfay uoryay nfray itsay avajay ropayramminggay


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...