Question
Complete the implementation of BlurbGenerator.java, which is called from Blurbs.java. The incomplete methods are makeWhoozit () makeYString() makeWhatzit() Submit BlurbGenerator.java . Blurbs.java /** * Solution
Complete the implementation of BlurbGenerator.java, which is called from Blurbs.java. The incomplete methods are
makeWhoozit()
makeYString()
makeWhatzit()
Submit BlurbGenerator.java.
Blurbs.java
/** * Solution to Programming Project 17.5 * * @author Java Foundations */ import java.util.Scanner;
public class Blurbs { /** * Generates a series of Blurbs (a word in an alien language). */ public static void main(String args[]) { BlurbGenerator blurbMaker = new BlurbGenerator(); Scanner scan = new Scanner(System.in);
System.out.println("How many blurbs would you like? "); int numBlurbs = scan.nextInt();
for (int i = 1; i <= numBlurbs; i++) { System.out.println("Blurb #" + i + ": " + blurbMaker.makeBlurb()); } } }
BlurbGenerator.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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started