Question

In Java pleaseThe purpose of this assignment is to help you learn Java identifiers, assignments, input/output nested if and if/else stateme

Question 2-String variables/Selection & loops. (8.5 points) Write a complete Java program which prompts the user for a sentencterminsted A2 UbbiDubbi lava Applicationl CProgram Files lavejrel 80 18binjavwwese(Mey 21, 2019,94706 Nancys English to Ubb

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 dubbi and displays the translated sentence. Ubbi dubbi works by adding ub before each vowel sound in a syllable. For example, hello becomes hubellubo. The word speak has the vowel sound ea, so in Ubbi dubbi it becomes spubeak. Tidbit: For those who are fans of The Big Bang Theory, Ubbi dubbi was used between Penny and Amy in season 10 episode 7 as a means of having a secret conversation, to counter Sheldon and Leonard's Klingon. Link to the video: ch? (From https://en.wikipedia.org/wiki/Ubbi_dubbi) ifie To simplify things for this assignment, 1. The vowels are a, e, i, o and u. 2. In the case that a word has 2 vowels following one another we only place ub in front of the 1st vowel. So zoom would be zuboom and not zuboubom. Similarly, steak would be stubeak and not stubeubak. (Figure 9) For words that are 1 character or 2 character long we add ub in front of each character whether they are vowels or consonants. (Figure 7) 4. If e is the last character of the word, we don't add ub in front of it. For example, the word one is translated as ubone and not ubonube.(Figure 9, last word) 5. Any other characters (punctuations, digits) are treated as non-vowels. (Figure 8) ns For this assignment you can assume that 1. There is exactly 1 space between words. 2. The entered string does not start nor end with a space. 3. All words are in lower case letters. 4. The sentence has at least one non-blank character Following are some sample outputs (Figures 6 to 9) to illustrate the expected behaviour of your program. Your program should work for any input, not just the ones in the samples below. The text in green is user input. You can change the format and/or content of the output as long as it still conveys the same information. COMP248/Summer 2019 Assignment 2 Page 4 of
cterminsted A2 UbbiDubbi lava Applicationl CProgram Files lavejrel 80 18binjavwwese(Mey 21, 2019,94706 Nancy's English to Ubbi Dubbi Translator Progran Plesse enter the English sentence you want tanslated into Ubbi Dubbi (Be sure to have 1 space butween words and to not have any spaces at the front and end of the sentence) rษslated sentence: Have fun speaking it!! Figure 6-Example with a single 1-character word sentence Problems Jevadoc Declaration Console cterminated A2 UbbiDubbi (Jlava Application CAProgram Fileslevajrel 80 181binljavaw.exe (Mey 21, 2019,931:39 P Nancy's English to Ubbi Dubbi Translator Progran Please enter the English sentence you want tanslated into Ubbi Dubbi (Be sure to have 1 space butween words and to not have any spaces at the front and end of the sentence) Translated sentence ubi ubaube Have fun speaking it!m Figure 7-Example with I-character and 2-characters long words Problems lavadocDeclarationConsole terminated A2 UbbiDubbi Java Application) CProgram FilesJavaljrel 80 181binjavaw.exe May 21, 2019, 9:3300 Nancy's English to ubbi Dubbi Translator Progran Please enter the English sentence you want tanslated into Ubbi Dubbi (Be sure to have 1 space bwtween words and to not have any spaces at the front and end of the sentence) an having fun with ubbi dubbi Translated sentence: ubi ubaubn hubavubing fubun wubith ububbubi dububbubi Have fun speaking itl! Figure 8-Example with mixed words and punctuation Problems JavedocDeclaration Console cterminatedb A2 UbbiDubbi (Java Application) CAProgram Files'Javalirel8.0 1811binljavaw.ee (May 21, 2019, 943:18P Nancy's English to Ubbi Dubbi Translator Progran Please enter the English sentence you want tanslated into Ubbi Dubbi le sure to have 1 space bwtween words and to not have any spaces at the front and end of the sentence) e aroon moon is aalways sooo n1се ranslated sentences The nubaruboon suboon ublubs ubaalwubays subooo nubice Have fun speaking itl Assume T is t Figure 9- Example wih words with 2 or more vowels following each other and a word that ends in e COMP248/Summer 2019 Assignment 2 Page 5 of
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. 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

// UbbiDubbi.java

import java.util.Scanner;

public class UbbiDubbi {

      // method to translate a word into corresponding word in ubbi dubbi

      static String translate(String word) {

            // declaring an empty string

            String ubbi = "";

            // if word length is 2 or less, adding ub before every letter

            if (word.length() <= 2) {

                  // adding one ub before first letter

                  ubbi += "ub" + word.charAt(0);

                  // if there is a second letter, adding one ub before second letter

                  if (word.length() == 2) {

                        ubbi += "ub" + word.charAt(1);

                  }

                  // returning it

                  return ubbi;

            }

            // a flag to check if previous character has been a vowel, so that when

            // 2 or more vowels come together, only one ub is added before them

            boolean prevVowel = false;

            // looping through each letter in word

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

                  // checking if current character is a vowel and previous character

                  // is not a vowel

                  if (isVowel(word.charAt(i)) && !prevVowel) {

                        // if this is the last character and the character is 'e',

                        // adding no 'ub'

                        if (i == word.length() - 1 && word.charAt(i) == 'e') {

                              ubbi += word.charAt(i);

                        } else {

                              // else, adding ub before character and appending to ubbi

                              // variable

                              ubbi += "ub" + word.charAt(i);

                        }

                        // turning prevVowel to true

                        prevVowel = true;

                  } else {

                        // simply appending current char to ubbi

                        ubbi += word.charAt(i);

                        // turning prevVowel to false if this character is not a vowel

                        if (!isVowel(word.charAt(i)))

                              prevVowel = false;

                  }

            }

            return ubbi;

      }

      // a method to check if a character is a vowel

      static boolean isVowel(char c) {

            // defining a String containing vowels

            String vowels = "aeiou";

            String chr = "" + c;

            // checking if chr is in vowels

            if (vowels.contains(chr.toLowerCase())) {

                  return true; // c is a vowel

            }

            // c is not a vowel

            return false;

      }

      public static void main(String[] args) {

            // defining a Scanner, reading input sentence

            Scanner scanner = new Scanner(System.in);

            System.out.println("Please enter the sentence: ");

            String sentence = scanner.nextLine();

            // splitting sentence into array of words

            String words[] = sentence.split(" ");

            System.out.println("Translated sentence:");

            // looping through each word and printing translated word

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

                  System.out.print(translate(words[i]) + " ");

            }

            System.out.println();

      }

}

/*OUTPUT (multiple runs)*/

Please enter the sentence:

i am having fun with ubbi dubbi!

Translated sentence:

ubi ubaubm hubavubing fubun wubith ububbubi dububbubi!

Please enter the sentence:

the maroon moon is aalways sooo nice

Translated sentence:

the mubaruboon muboon ubiubs ubaalwubays subooo nubice

Add a comment
Know the answer?
Add Answer to:
In Java please Only use methods in the purpose. Thank you The purpose of this assignment is to help you learn Java iden...
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
  • String variables/Selection & loop Write a complete Java program which prompts the user for a sentence on one line wh...

    String variables/Selection & loop 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 dubbi and displays the translated sentence. Ubbi dubbi works by adding ub before each vowel sound in a syllable. For example, hello becomes hubellubo. The word speak has the vowel sound ea, so in Ubbi dubbi it becomes spubeak....

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

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

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

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • JAVA Primitive Editor (Please help, I am stuck on this assignment which is worth a lot...

    JAVA Primitive Editor (Please help, I am stuck on this assignment which is worth a lot of points. Make sure that the program works because I had someone answer this incorrectly!) The primary goal of the assignment is to develop a Java based primitive editor. We all know what an editor of a text file is. Notepad, Wordpad, TextWrangler, Pages, and Word are all text editors, where you can type text, correct the text in various places by moving the...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

  • JAVA Primitive Editor The primary goal of the assignment is to develop a Java based primitive...

    JAVA Primitive Editor The primary goal of the assignment is to develop a Java based primitive editor. We all know what an editor of a text file is. Notepad, Wordpad, TextWrangler, Pages, and Word are all text editors, where you can type text, correct the text in various places by moving the cursor to the right place and making changes. The biggest advantage with these editors is that you can see the text and visually see the edits you are...

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