
Complete the implementation of BlurbGenerator.java, which is called from Blurbs.java. The incomplete methods are
-
- makeWhoozit()
- makeYString()
- makeWhatzit()
Submit BlurbGenerator.java.
Blurbs.java
import java.util.Random;
/**
* In the language of an alien race, all words take the form of Blurbs.
* A Blurb is a Whoozit followed by one or more Whatzits.
* A Whoozit is the character 'x' followed by zero or more 'y's.
* A Whatzit is a 'q' followed by either a 'z' or a 'd', followed
* by a Whoozit.
*
* Solution to Programming Project 17.5
*
* @author Java Foundations
*/
public class BlurbGenerator {
private Random gen;
/**
* Instantiates a random number generator needed for blurb creation.
*/
public BlurbGenerator() {
gen = new Random();
}
/**
* Generates and returns a random Blurb. A Blurb is a Whoozit
* followed by one or more Whatzits.
*/
public String makeBlurb() {
return makeWhoozit() + makeMultiWhatzits();
}
/**
* Generates a random Whoozit. A Whoozit is the character 'x'
* followed by zero or more 'y's.
*/
private String makeWhoozit() {
System.out.println("makeWhoozit() unimplemented.");
String whoozit = "";
return whoozit;
}
/**
* Recursively generates a string of zero or more 'y's.
*/
private String makeYString()
{
System.out.println("makeYString() unimplemented.");
String yString = "";
return yString;
}
/**
* Recursively generates a string of one or more Whatzits.
*/
private String makeMultiWhatzits() {
String whatzits = makeWhatzit();
if (gen.nextBoolean()) {
whatzits += makeMultiWhatzits();
}
return whatzits;
}
/**
* Generates a random Whatzit. A Whatzit is a 'q' followed by
* either a 'z' or a 'd', followed by a Whoozit.
*/
private String makeWhatzit() {
System.out.println("makeWhatzit() unimplemented.");
String whatzit = "";
return whatzit;
}
} // class BlurbGenerator

Algorithm:
- The
BlurbGenerator
class initializes aRandom
generator. - The
makeBlurb()
method returns a randomWhoozit
followed by one or moreWhatzit
generated by themakeMultiWhatzits()
method. - The
makeWhoozit()
method returns the string "x" followed by zero or more "y" generated by themakeYString()
method. - The
makeYString()
method recursively generates a string of zero or more "y". If a random boolean value is true, it adds a "y" to the string and calls itself again. - The
makeWhatzit()
method generates aWhatzit
which starts with the string "q" and appends either "z" or "d" depending on a random boolean value. It then callsmakeWhoozit()
to generate the rest of theWhatzit
. - The
makeMultiWhatzits()
method generates a string of one or moreWhatzit
usingmakeWhatzit()
. If a random boolean value is true, it appends the result of a recursive call to itself. It returns the concatenated string of all theWhatzit
generated.
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images

- Consider the following Java class contained in Mystery.java, and compiled: public class Mystery { public static void main(String[] args) { int current = = -1: int count = O: while (!Stdln.isEmpty()) { }}} int x = stdin.readlnt(): if (x != current) { } if (count > 0) count++; % more input1.txt 0 0 0 0 1 1 1 1 StdOut.print(count); current = x; count = 0; A. Assume the contents of the file input.txt are given below (note: the line starting with % is what you type on the command line prompt / the terminal; what follows is the actual content of the file input1.txt). Suppose that you execute the following command. What is standard output? Write your answer in the space provided. % java-introcs Mystery < input1.txt B. Repeat the previous question, but with the following input file. % more input2.txt 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1 % java-introcs Mystery < input2.txt ted on thearrow_forwardGiven string inputStr on one line and integers idx1 and idx2 on a second line, output "Match found" if the character at index idx1 of inputStr is equal to the character at index idx2. Otherwise, output "Match not found". End with a newline. Ex: If the input is: eerie 4 1 then the output is: Match found Note: Assume the length of string inputStr is greater than or equal to both idx1 and idx2.arrow_forwardStringFun.java import java.util.Scanner; // Needed for the Scanner class 2 3 /** Add a class comment and @tags 4 5 */ 6 7 public class StringFun { /** * @param args not used 8 9 10 11 12 public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Please enter your first name: "); 13 14 15 16 17 18 System.out.print("Please enter your last name: "); 19 20 21 //Output the welcome message with name 22 23 24 //Output the length of the name 25 26 27 //Output the username 28 29 30 //Output the initials 31 32 33 //Find and output the first name with switched characters 34 //All Done! } } 35 36 37arrow_forward
- Use the Java program in below, implement encapsulation on the property name, and use getters and setters to unhide the name: class Animal1{String name; public void eat(){System.out.println("I can eat");}} class Dog extends Animal1{public void display(){System.out.println("My name is " + name);}} public class Lab06_A{public static void main(String[] args){ Dog labrador = new Dog(); labrador.name = "Rohu";labrador.display(); labrador.eat();} }arrow_forwardHow do I fix the error Java? ReceiptMaker.java:6: error: invalid method declaration; return type required ItemClass(String name, double price) { ^ Code: import java.util.Scanner; public class FinalExamAnswers{ public static void main(String [] args) { manipulateString(); //calls function } //your code here public static void manipulateString() { Scanner sc=new Scanner(System.in); //create Scanner instance System.out.print("Enter a sentence: "); String sentence=sc.nextLine(); //input a sentence String[] words=sentence.split(" "); //split the sentence at space and store it in array for(int i=0;i<words.length;i++) //i from 0 to last index { if(i%2==0) //if even index words[i]=words[i].toUpperCase(); //converted to upper case else //if odd index words[i]=words[i].toLowerCase(); //converted to lower case }…arrow_forwardI have to fill out the code for Team.javaarrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY





