Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

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

A Whatzit is a q followed by either a z or a d followed by a Whoozit.

1. Design and implement a program that generates blurbs and asks the user for how many blurbs they would like.

2. Design and implement a recursive program that check a given string to be a Blurb or not. The program should repetitively prompt the users for more string to check till the user decide to stop.

I already did part one here, but I still need help with part 2.

import java.util.Random; import java.util.Scanner;

public class BlurbyBlurb //naming corresponds to { // random number generator used by all functions public static Random r = new Random(); public static String Blurb() { String result = Whoozit(); // A Blurb is a Whoozit int num = r.nextInt(9) + 1; for (int i = 0; i < num; i++) //followed by one or more Whatzits. { result += Whatzit(); } return result; }

public static String Whoozit() { String result = "x"; // A Whoozit is the character 'x' ... int num = r.nextInt(9); for (int i = 0; i < num; i++) { result += "y"; // followed by zero or more 'y's. } return result; }

public static String Whatzit() { String result = "q"; // A Whatzit is a 'q' int num = r.nextInt(2); if (num == 0) { result += "z"; // followed by either a 'z' or a 'd', } else // (num == 1) { result += "d"; } result += Whoozit(); // followed by a Whoozit. return result; }

public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("This program makes Blurbs."); System.out.println("How many blurbs do you want?"); int n = scan.nextInt(); while (n > 0) { System.out.println(Blurb()); n--; } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

13th Edition Global Edition

1292263350, 978-1292263359

More Books

Students also viewed these Databases questions