Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

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

 

Expert Solution
Check Mark
Step 1

Algorithm:

  1. The BlurbGenerator class initializes a Random generator.
  2. The makeBlurb() method returns a random Whoozit followed by one or more Whatzit generated by the makeMultiWhatzits() method.
  3. The makeWhoozit() method returns the string "x" followed by zero or more "y" generated by the makeYString() method.
  4. 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.
  5. The makeWhatzit() method generates a Whatzit which starts with the string "q" and appends either "z" or "d" depending on a random boolean value. It then calls makeWhoozit() to generate the rest of the Whatzit.
  6. The makeMultiWhatzits() method generates a string of one or more Whatzit using makeWhatzit(). If a random boolean value is true, it appends the result of a recursive call to itself. It returns the concatenated string of all the Whatzit generated.
Knowledge Booster
Background pattern image
Computer Engineering
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY