Question

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 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:

media%2Fbd2%2Fbd29d93b-7ab9-40d1-81f3-96

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 a text file and create a second text file that contains the original text but with every word converted to “Pig-Latin....
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
  • 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...

  • 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...

  • 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...

  • 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”...

  • Exercise 3) Creating a QT program to search for Customer Phone Number : Create a text...

    Exercise 3) Creating a QT program to search for Customer Phone Number : Create a text file (customer.txt) and put names and phone numbers into it. each name has to have its own phone number right under it. In the QT window, the user has to enter a name and the program prints the phone number related to it. NB: If the user input a name that doesn't exist, the program should print an error message. Text file example: QT...

  • This program is used to create a phonebook for storing contact information into a text file....

    This program is used to create a phonebook for storing contact information into a text file. The program begins by asking the user to provide a name for the file that will contain their phone book information. It will then ask the user to provide the names and numbers of their contacts. It should keep asking the user for contact information until they type in Done (case-sensitive). After the user types Done, store all contact information into the file name...

  • Write a java netbeans program. Project Two, Super Bowl A text file named “SuperBowlWinners.txt” contains the...

    Write a java netbeans program. Project Two, Super Bowl A text file named “SuperBowlWinners.txt” contains the names of the teams that won the Super Bowl from 1967 through 2019. Write a program that repeatedly allows a user to enter a team name and then displays the number of times and the years in which that team won the Super Bowl. If the team entered by the user has never won the Super Bowl, report that to the user instead. For...

  • CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the fil...

    CSC110 Lab 6 (ALL CODING IN JAVA) Problem: A text file contains a paragraph. You are to read the contents of the file, store the UNIQUEwords and count the occurrences of each unique word. When the file is completely read, write the words and the number of occurrences to a text file. The output should be the words in ALPHABETICAL order along with the number of times they occur and the number of syllables. Then write the following statistics to...

  • How can I create Loops and Files on Java? • Create a program that reads a...

    How can I create Loops and Files on Java? • Create a program that reads a list of names from a source file and writes those names to a CSV file. The source file name and target CSV file name should be requested from the user • The source file can have a variable number of names so your program should be dynamic enough to read as many names as needed • When writing your CSV file, the first row...

  • C++ Lab 1. Read in the contents of a text file up to a maximum of...

    C++ Lab 1. Read in the contents of a text file up to a maximum of 1024 words – you create your own input. When reading the file contents, you can discard words that are single characters to avoid symbols, special characters, etc. 2. Sort the words read in ascending order in an array (you are not allowed to use Vectors) using the Selection Sort algorithm implemented in its own function. 3. Search any item input by user in your...

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
ADVERTISEMENT