In Java please
Only use methods in the purpose.
Thank you
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
In Java please Only use methods in the purpose. Thank you The purpose of this assignment is to help you learn Java iden...
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 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 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 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 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 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 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: 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: 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 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...