Question

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 files English.java & PigLatinator.java TWO CLASSES PLEASE!

make sure that there are two files English.java & PigLatinator.java TWO CLASSES PLEASE!

make sure that there are two files English.java & PigLatinator.java TWO CLASSES PLEASE!

make sure that there are two files English.java & PigLatinator.java TWO CLASSES PLEASE!

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

Here is the completed code for the two classes. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

//English.java (interact with the user)

import java.util.Scanner;

public class English {

    public static void main(String[] args) {

        // setting up a Scanner

        Scanner scanner = new Scanner(System.in);

        String ch = "y";

        // /looping until user chooses to quit

        while (ch.equalsIgnoreCase("y")) {

             // asking and reading a sentence in English

             System.out.print("Enter a sentence in English (space separated): ");

             String sentence = scanner.nextLine().toUpperCase();

             // displaying the read sentence and the corresponding translation in

             // pig latin

             System.out.println("English:   " + sentence);

             System.out.println("Pig Latin: " + PigLatinator.convert(sentence));

            

             //asking user if he/she likes to convert another sentence

             System.out.print("\nDo you want to convert another? (y/n) ");

             ch = scanner.nextLine();

             System.out.println();

        }

    }

}

//PigLatinator.java (contains method to convert english to pig latin)

public class PigLatinator {

    /**

    * method to convert a line of text to pig latin

    *

    * @param text

    *            sentence containing space seperated list of words

    * @return a String containing each word converted to pig latin, space

    *         separated

    */

    public static String convert(String text) {

        // converting text to upper case and splitting by space

        String words[] = text.toUpperCase().split(" ");

        // defining an empty string

        String converted = "";

        // looping through each word

        for (int i = 0; i < words.length; i++) {

             // ensuring that word isnt empty

             if (words[i].length() > 0) {

                 // taking out a substring containing string without first

                 // letter, appending first letter at the end, followed by 'AY'

                 String piglatin = words[i].substring(1) + words[i].charAt(0)

                         + "AY";

                 // appending to converted text followed by a space

                 converted += piglatin + " ";

             }

        }

        // returning the converted text after removing trailing/leading spaces

        return converted.trim();

    }

}

/*OUTPUT*/

Enter a sentence in English (space separated): I SLEPT MOST OF THE NIGHT

English:   I SLEPT MOST OF THE NIGHT

Pig Latin: IAY LEPTSAY OSTMAY FOAY HETAY IGHTNAY

Do you want to convert another? (y/n) y

Enter a sentence in English (space separated): java programming is fun

English:   JAVA PROGRAMMING IS FUN

Pig Latin: AVAJAY ROGRAMMINGPAY SIAY UNFAY

Do you want to convert another? (y/n) y

Enter a sentence in English (space separated): ay ay

English:   AY AY

Pig Latin: YAAY YAAY

Do you want to convert another? (y/n) n

Add a comment
Know the answer?
Add Answer to:
JAVA PROGRAMMING LANGUAGE!!!! Pig Latin Write a program that reads a sentence as input and converts...
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
  • Assignment 5 Due Apr 5 by 11:59pm Points 100 Submitting a file upload A5 Wrapper Classes "Pig Lat...

    Assignment 5 Due Apr 5 by 11:59pm Points 100 Submitting a file upload A5 Wrapper Classes "Pig Latin" Access A5 from pdf assigament file t Turn in the following files aSmain java program compile and run screenshots design document AS 15. 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...

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

  • In java: A fun language: f you recently ate at Chipotle, you may have received a...

    In java: A fun language: f you recently ate at Chipotle, you may have received a brown paper bag with gibberish letters written on it: “AKINGMAY AWAY IGPAY EALDAY ABOUTWAY IGPAY ATINLAY”. In fact this message is written in Piglatin, a simple but fictitious language. Piglatin converts a word in English using the following two rules: If the letter begins with a vowel, then “WAY” is appended to the word. If the letter begins with a consonant (a letter other...

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

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

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

  • please write a C++ code Problem A: Word Shadow Source file: shadow.cpp f or java, or.cj...

    please write a C++ code Problem A: Word Shadow Source file: shadow.cpp f or java, or.cj Input file: shadow.in in reality, when we read an English word we normally do not read every single letter of that word but rather the word's "shadow" recalls its pronunciation and meaning from our brain. The word's shadow consists of the same number of letters that compose the actual word with first and last letters (of the word) in their original positions while the...

  • In Java please Only use methods in the purpose. Thank you The purpose of this assignment is to help you learn Java iden...

    In Java please Only use methods in the purpose. Thank you The purpose of this assignment is to help you learn Java identifiers, assignments, input/output nested if and if/else statements, switch statements and non-nested loops. Purpose Question 2-String variables/Selection & loops. (8.5 points) Write a complete Java program which prompts the user for a sentence on one line where each word is separated by one space, reads the line into one String variable using nextline), converts the string into Ubbi...

  • Your next programming assignment at the Research Center is to write a program that reads data...

    Your next programming assignment at the Research Center is to write a program that reads data from a file and produces a report of rainfall for that period of time. The program should read the starting month name from the data file, then read an ending month name, followed by reading in monthly rainfall amounts for each of the months from the starting month through the ending month. As it reads the monthly totals, it should sum (accumulate) the rainfall...

  • Can somebody help me with Java programming? please be brief and explain the process and carefully...

    Can somebody help me with Java programming? please be brief and explain the process and carefully follow the step by step instruction. Thanks Homework 12.1 - Write a program that generates five random sentences (like mad libs), prints them to a file, then reads in the sentences and prints them to the console. Start by creating four string arrays for nouns, verbs, colors, and places. They should store at least 5 of each type of word. You can have more...

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