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!
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
JAVA PROGRAMMING LANGUAGE!!!! Pig Latin Write a program that reads a sentence as input and converts...
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 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...
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. #############################################################...
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 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.” 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...
Im writing a c++ program to translate a sentence to pig latin. But I keep getting an error where it only prints out the "ay" part. Not sure where I'm wrong here. string piglatin(string); string substr(string, int&); int main () //begin main { string input; cout<<"Enter a sentence to convert: "; getline(cin, input); cout<<"Converted to Pig Latin: "<<piglatin(input)<<endl<<endl; //cout << "Search for another value? (Y/N)"; //to convert again system("pause"); return 0; } string piglatin(string input) //piglatin function { int len,...
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 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...
Programming Language is Java Lab 1: Programming Exercises Input/Process/Output 1) Run the Numbers. Write a program with two input values. The program should display the sum, difference, quotient, product, and average of the two numbers. 2) Jake’s Problem. Jake has a car with an 8-gallon fuel tank. Jake fills his tank with gas and drives 60 miles to a friend’s house. When he gets to his friend’s house, he has 6 gallons left in his fuel tank. Write a program...