Question

Pig Latin Translator in Java The goal here is to read in the characters stored in...

Pig Latin Translator in Java

The goal here is to read in the characters stored in a text file and create a second text file that contains the original text but with every word converted to “Pig-Latin.” The rules used by Pig Latin are as follows: • If a word begins with a vowel, just as "yay" to the end. For example, "out" is translated into "outyay". • If it begins with a consonant, then we take all consonants before the first vowel and we put them on the end of the word and add “ay”. For example, "which" is translated into "ichwhay". CIT111 Introduction to Programming: Java You can test your results by going to Pig Latin translation sites such as https://www.wordplays.com/pig-latin. Program Requirements The program should operate in a loop, allowing the user to enter new file names, or terminate the program. When an input file name is entered, if the file does not exist, the user should be prompted to enter the name again. When an output file name is entered, if the file does exist, the user should be informed and given the option to overwrite the file or to enter a new name. When both file names have passed muster, the program will perform the translation and create the output file. The program will indicate that the operation has completed and give the user the option to display the output results on the screen. If the user chooses to do so, the output file contents will be displayed. If not, the program will return to the file name prompts. Handle uppercase characters intelligently. For example, “Jack” should appear as “Ackjay” in Pig-Latin, and not as “ackJay”. Punctuation should end up in the right place — either just before the beginning of a word or right at the end of the word.

You should strive to incorporate all aspects of good programming practice. This includes input validation, commenting, use of methods, arrays and collection classes, etc.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

main.java

import java.util.Scanner;

public class Main {

private static Scanner sc = new Scanner(System.in);

public static void main(String[] args) {

System.out.print("Enter string to be converted: ");

final String inp = sc.nextLine();

sc.close();

String[] arr = inp.split(" ");

String res = "";

String res2 = "";

for (int x = 0; x < arr.length; x++) {

String res1 = pigLatinConversion(arr[x]);

res += res1 + " ";

res2 = res.toUpperCase().charAt(0) + res.substring(1);

}

System.out.println("Original String: " + inp);

System.out.println("Pig Latin: " + res2 + "\n");

}

public static String pigLatinConversion(String arr) {

String low = arr.toLowerCase();

int positions = -1;

char choices;

for (int x = 0; x < low.length(); x++) {

choices = low.charAt(x);

if (checkForVowel(choices)) {

positions = x;

break;

}

}

if (positions == 0) {

return low + "yay";

} else {

String str1 = low.substring(positions);

String str2 = low.substring(0, positions);

return str1 + str2 + "ay";

}

}

public static Boolean checkForVowel(char choices) {

if (choices == 'a' || choices == 'e' || choices == 'i' || choices == 'o' || choices == 'u' || choices == 'y') {

return true;

}

return false;

}

}

Output:

Add a comment
Know the answer?
Add Answer to:
Pig Latin Translator in Java The goal here is to read in the characters stored in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Pig Latin Translator in Java The goal here is to read in the characters stored in a text file and create a second text file that contains the original text but with every word converted to “Pig-Latin....

    Pig Latin Translator in Java The goal here is to read in the characters stored in a text file and create a second text file that contains the original text but with every word converted to “Pig-Latin.” The rules used by Pig Latin are as follows: • If a word begins with a vowel, just as "yay" to the end. For example, "out" is translated into "outyay". • If it begins with a consonant, then we take all consonants before...

  • In C Sixth: Pig Latin (10 Points) For this part of the assignment, you will need...

    In C Sixth: Pig Latin (10 Points) For this part of the assignment, you will need to write a program that reads an input string representing a sentence, and convert it into pig latin. We'll be using two simple rules of pig latin: 1. If the word begins with a consonant then take all the letters up until the first vowel and put them at the end and then add "ay" at the end. 2. If the word begins with...

  • Pig Latin program using Linked Lists C++

    Write a program that prompts the user to input a string and then outputs the string in the pig Latin form. The rules for converting a string into pig Latin form are asfollows:a. If the string begins with a vowel, add the string "-way" at the end of the string. for example, the pig Latin form of the string "eye" is "eye-way".b. If the string does not begin with a vowel, first ass "-" at the end of the string....

  • Write the Java code for the class WordCruncher. Include the following members:

    **IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...

  • In C please Pig latin has two very simple rules: If a word starts with a...

    In C please Pig latin has two very simple rules: If a word starts with a consonant move the first letter(s) of the word, till you reach a vowel, to the end of the word and add "ay" to the end. have ➞ avehay cram ➞ amcray take ➞ aketay cat ➞ atcay shrimp ➞ impshray trebuchet ➞ ebuchettray If a word starts with a vowel add "yay" to the end of the word. ate ➞ ateyay apple ➞ appleyay...

  • Please use PYTHON3 to Create a program that translates English into Pig Latin. The function will...

    Please use PYTHON3 to Create a program that translates English into Pig Latin. The function will take the first letter of each word in the sentence only if it’s a not a vowel, and place it at the end of the word followed by “ay”. Your program must be case insensitive. You must write the function translate() that takes in a single English word and returns its Pig Latin translation. Remember translate must take only one word as input. #############################################################...

  • use C++ Pig Latin Background Pig latin is a "language” where you take the regular English...

    use C++ Pig Latin Background Pig latin is a "language” where you take the regular English Word, remove the first letter, place it on the end of the word, and then append "ay" to the end of the word. Pig Latin = Igpay Atinlay Functionality 1) Prompt the user to enter any input string (I will test it with multiple words). 2) After receiving and storing (if needed) their input, change their words to Pig Latin by placing the first...

  • There is a children's "secret language" called "Pig Latin" which supposedly allows conversation the uninformed (such...

    There is a children's "secret language" called "Pig Latin" which supposedly allows conversation the uninformed (such as parents) cannot understand. The rules are: If a word begins with a vowel (aeiou) then append "way" to the word. For example, "Aggie" becomes "Aggieway". Otherwise, remove the consecutive non-vowels from the beginning of the word, append them to the end of the word, and append "ay" to the word. For example, "whoop" becomes "oopwhay". Write a program named hw5pr1.cpp which reads words...

  • JAVA PROGRAMMING LANGUAGE!!!! Pig Latin Write a program that reads a sentence as input and converts...

    JAVA PROGRAMMING LANGUAGE!!!! Pig Latin Write a program that reads a sentence as input and converts each word to "Pig Latin". In one version of Pig Latin, you convert a word by removing the first letter, placing that letter at the end of the word, and then appending "ay" to the word. Here is an example: English:                       I SLEPT MOST OF THE NIGHT Pig Latin :                   TAY LEPTSAY OSTMAY FOÀY HETAY 1GHTNAY make sure that there are two...

  • Design and code a SWING GUI to translate text entered in English into Pig Latin. You...

    Design and code a SWING GUI to translate text entered in English into Pig Latin. You can assume that the sentence contains no punctuation. The rules for Pig Latin are as follows: For words that begin with consonants, move the leading consonant to the end of the word and add “ay”. Thus, “ball” becomes “allbay”; “button” becomes “uttonbay”; and so forth. For words that begin with vowels, add “way’ to the end of the word. Thus, “all” becomes “allway”; “one”...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT