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

Use the method: public static String convertToPigLatin (String inStr) { String r

ID: 3642076 • Letter: U

Question

Use the method:

public static String convertToPigLatin (String inStr) {
String ret = "";
char first = inStr.toLowerCase().charAt(0);
if(first == 'a' || first == 'e' || first == 'i' || first == 'o' || first == 'u') {
ret = inStr.toLowerCase() + "way";
}
else {
ret = inStr.substring(1).toLowerCase() + first + "ay";
}
return ret;
}

Write a program that
1) Open a file for input called pigLatinIn.txt, which will be provided to you. This file will consist of one English word per line.
2) Open a file for output called pigLatinOut.txt.
3) Your program will then read the input file, use the convertToPigLatin() method to determine the pig Latin equivalent to the word, then write the following to the output file:

English word Pig Latin Word
------------ --------------
cabin abin-cay
apple apple-way

4) Print out the results in all lower case.

Explanation / Answer

import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; public class StringUtil { public static String convertToPigLatin(String english) { String englishWord, pigLatin = null; englishWord = english; if (englishWord.charAt(0) == 'a' || englishWord.charAt(0) == 'e' || englishWord.charAt(0) == 'i' || englishWord.charAt(0) == 'o' || englishWord.charAt(0) == 'u') { pigLatin = englishWord + "way"; } else { char firstChar = englishWord.charAt(0); pigLatin = englishWord + firstChar + "ay"; } return pigLatin; } public static void main(String s[]) { List strList = new ArrayList(); List resList = new ArrayList(); try { FileReader fileReader = new FileReader("pigLatinIn.txt"); BufferedReader bufRead = new BufferedReader(fileReader); String thisLine = null; while ((thisLine = bufRead.readLine()) != null) { StringTokenizer st = new StringTokenizer(thisLine); while (st.hasMoreTokens()) { strList.add(st.nextToken()); } } Iterator iter = strList.iterator(); while (iter.hasNext()) { String str = iter.next(); String res = convertToPigLatin(str); resList.add(res); } FileWriter fileWriter = new FileWriter("pigLatinOut.txt"); for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote