Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Pig latin works this way: if a word begins with a vowel (a-e-i-o-u), then \"ay\"

ID: 3810467 • Letter: P

Question

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").

The PigDriver class reads in multiple lines of text, ending finally with two carriage returns. At each line entered, the pigConvert method in your PigLatin class is called to convert that string to pig latin form. After the reading segment ends, your PigLatin class should then print the pig latin translation of the input text- the pigReport method. 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.


On this input:


The following output was produced:

Requirements:

Your Piglatin class must define and implement the pigConvert method, which takes a line of text as a parameter and does not return a value. It does the conversion to pig latin and stores the result.

Your Piglatin class must define and implement the pigReport method, which takes no parameters and prints a report (as specified above) to the console.

You must use the String method split with this parameter: "[ ,.!?;:]" AND NO OTHER in your Piglatin class.

You may not use the ArrayList class for this project.

Tips:

NOTICE the class name is Piglatin, NOT PigLatin!!

Write additional helper methods to make your development easier.

Use an appropriate data structure (an array) to store any values you need to store.



Enter your Piglatin class here:

Explanation / Answer

Java Program :

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.io.*;
import java.util.*;

class Piglatin {

//StringBuilder to build the result
private StringBuilder result;

Piglatin() {
result = new StringBuilder();
}

//This method converts the given string
public void pigConvert(String t) {
if (t.charAt(0) == 'a' || t.charAt(0) == 'e' || t.charAt(0) == 'i' || t.charAt(0) == 'o' || t.charAt(0) == 'u') {
t = t.concat("ay");
} else {
t = t.concat(t.charAt(0) + "ay").substring(1);
}
result.append(t + " ");
}
  
//This method prints the result built
public void pigReport() {
System.out.println(result);
result = new StringBuilder();
}
}

class PigDriver {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String t = " ";
Piglatin p = new Piglatin();
while (true) {
t = scan.nextLine();
//If length is 0, break;
if (t.length() == 0) {
break;
}
String str[] = t.split(" ");
for (String x : str) {
//If the string contains, special characters, ignore them
if (x.endsWith(",") || x.endsWith(".") || x.endsWith("!")) {
x = x.substring(1, x.length() - 1);
}
x = x.toLowerCase();
p.pigConvert(x);
}
p.pigReport();
}
}

}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

OUTPUT:

Now is the time,
for all good, and I mean very good men and women,
to visit their grandmothers!
ownay isay hetay imeay
orfay allay ooday anday iay eanmay eryvay oodgay enmay anday omenay
otay isitvay heirtay andmothersray