Question

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 than a vowel), then the first letter of the word is moved to the end, and then “AY” is appended to it. Using these rules, one can decode the Chipotle message to “MAKING A PIG DEAL ABOUT PIG LATIN”.

What to do: Write a method that codes and returns an English sentence in Piglatin. Write tests for this method.

Abstraction: Can some of these operations be merged into a common higher-order-function? Determine if these operations can be expressed as a map, filter, fold/reduce, or a combination of them. If so, write these general-purpose methods and re-implement the above operations using them.

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

Note: Implemented the code. Please comment for further help. Please uprate.

Code:

Piglatin.java


public class Piglatin {
  
   String string;
  
   //constructor
   Piglatin(String text){
       this.string=text;
   }

   //creating Piglatin string
   public String createPiglatin(){
       //splitting string to individual words
       String[] words = string.split("\\s+");
       //making string empty
       string="";
       //loop for each word
       for(int i=0;i<words.length;i++){
           //convert to lowercase
           words[i]=words[i].toLowerCase();
           //if vowel then add way at the end
           if(words[i].charAt(0) =='a' ||words[i].charAt(0) =='e'||words[i].charAt(0) =='i'||words[i].charAt(0) =='o'||words[i].charAt(0) =='u'){
               words[i]=words[i]+"way";
           }else{
               //else remove first letter, add to end and then add ay at end
               words[i]=words[i].substring(1, words[i].length())+words[i].substring(0,1)+"ay";
           }
           //converting back to uppercase
           words[i]=words[i].toUpperCase();
           //making string again
           string=string+words[i]+" ";
       }
       //Trimming extra spaces
       string=string.trim();
       //return string
       return string;
   }
}

PiglatinTestCase.java

import static org.junit.Assert.*;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class PiglatinTestCase {

   //Piglatin object
   Piglatin obj;
   //setting and initializing
   @Before
   public void setUp() throws Exception {
       obj=new Piglatin("MAKING A PIG DEAL ABOUT PIG LATIN");
   }

   //checking if result is same
   @Test
   public final void testCreatePiglatinToPass() {
       Assert.assertEquals("AKINGMAY AWAY IGPAY EALDAY ABOUTWAY IGPAY ATINLAY", obj.createPiglatin());
   }
  
   @Test
   public final void testCreatePiglatinToFail() {
       Assert.assertEquals("AKINGMAY AWAY IGPAY EALDAY ABOUTWAY IGPAY", obj.createPiglatin());
   }

}

Output:

Tested with one pass and one fail case

This part seems to be irrelevant to the given question as no operation is mentioned. Please comment if you need help.

Abstraction: Can some of these operations be merged into a common higher-order-function? Determine if these operations can be expressed as a map, filter, fold/reduce, or a combination of them. If so, write these general-purpose methods and re-implement the above operations using them.

Add a comment
Know the answer?
Add Answer to:
In java: A fun language: f you recently ate at Chipotle, you may have received a...
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
  • 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...

  • Correct the syntax errors to allow the code to pass all of the provided doctests. You...

    Correct the syntax errors to allow the code to pass all of the provided doctests. You may have heard of "Pig Latin," a set of rules for modifying regular English to render it unintelligible to those who do not know the rules. This problem asks you to fix a function that will convert an English word to Pig Latin The rules for converting a word to Pig Latin are as follows: 1. If the word starts with a vowel, add...

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

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

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

  • 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 this lab, you may use MATLAB to implement the Recursion problems. Do not use a...

    In this lab, you may use MATLAB to implement the Recursion problems. Do not use a for or a while loop to implement a recursive function. 3. Recursion: Sort Game (One of the reasons why we sort) (25 points) Write a recursive function that guesses a number between 0 and x (x being an input number to the function). If you guess too high, it tells you that and continues. If you guess too low, it tells you that and...

  • cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having...

    cs55(java) please Part 1: You are a programming intern at the student transfer counselor's office. Having heard you are taking CS 55, your boss has come to ask for your help with a task. Students often come to ask her whether their GPA is good enough to transfer to some college to study some major and she has to look up the GPA requirements for a school and its majors in a spreadsheet to answer their question. She would like...

  • Please Use Python/IDLE language! Also, pleaseee include step by step algorithm. Python 3.4 Hawaiin Words program...

    Please Use Python/IDLE language! Also, pleaseee include step by step algorithm. Python 3.4 Hawaiin Words program help please. Hawaiian words can be intimidating to attempt to pronounce. Words like humuhumunukunukuapua'a look like someone may have fallen asleep on the keyboard. The language is actually very simple and only contains 12 characters; 5 vowels and 7 consonants. We are going to write a program that allows the user to enter a hawaiian word and give the pronunciation of the word or...

  • JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the...

    JAVA PROJECT Part 1 - Normalize Text The first thing we will do is normalize the input message so that it’s easier to work with. Write a method called normalizeText which does the following: Removes all the spaces from your text Remove any punctuation (. , : ; ’ ” ! ? ( ) ) Turn all lower-case letters into upper-case letters Return the result. The call normalizeText(“This is some \“really\” great. (Text)!?”) should return “THISISSOMEREALLYGREATTEXT” Part 2 - Obfuscation...

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