In the language of an alien race, all words take the form of Blurbs. A Blurb is
ID: 3815528 • Letter: I
Question
In the language of an alien race, all words take the form of Blurbs. A Blurb is a Whoozit followed by between zero and ten Whatzits. A Whoozit is the character 'x' followed by between one and ten 'y's. A Whatzit is a 'q' followed by either a 'z' or a 'd', followed by a Whoozit. Design and implement a recursive program that generates 10 random Blurbs in this alien language
Considering the language just discussed, write a program that reads a string from the user, and checks whether or not is a valid sentence. If it is valid, it prints "The word is fine.", otherwise it prints "The word is a mess!" The program should loop and ask the user for new input until they enter DONE. (Hint: try Whoozits first, followed by Whatzits, and then Blurbs. For each method, test it by running it on known valid strings generated by the methods you had to write for Q1.)
(run) x output SER200 HW xyyad2kyyazxyyyyyyyyyadzkyyyyyyadxyyyyyadxyadxyyyyadxyyyyyyyy xyyyyyyyadxyyyyyyyyazxyyyyyazxyqzxyyyadzkyyyyyyazxyyyyyyyyazxyyyyyyyyy 2kyyyyqzxyyyyyyyyyy 2kyyyyyyyyad2kyyyyyyyyqzxyyqdzkyyqd2kyyyyyyyqzxyyyyyyyyyyqdzkyyqzxyyy 2kyyyy xyyqdxyyyyyyyyqdzkyyyyyyy xyyyyyyyyyyazxyyyyyyadzkyyyyyyadxyyyyyazx yyyyyy xyadzkyyyyyyyyadzkyyyyyyyyadxyyazxyyyyyyyy xyyyyyyadzkyyyyyyyyyyadzkyyyyyyyyyazxyadxyyyyyyyyyyazxyyyyyyyyyy BUILD SUCCESSFUL (total time: 0 secondsExplanation / Answer
//CLASS WHOOZIT
import java.util.Random;
public class Whoozit
{
private String second;
private int num;
private Random rand;
private String Whoozit;
public Whoozit()
{
rand = new Random();
Whoozit = "x";
second = "y";
num = rand.nextInt(100);
makeWhoozit(Whoozit, second, num);
}
private void makeWhoozit(String x, String y, int times)
{
for(int counter = 0; counter < times; counter++)
{
Whoozit += second;
}
}
public String toString()
{
return Whoozit;
}
}
//CLASS WHATZIT
import java.util.Random;
public class Whatzit
{
private int choice;
private Random rand;
private Whoozit whoozit;
private String whatzit;
public Whatzit()
{
rand = new Random();
whoozit = new Whoozit();
whatzit = "q";
choice = rand.nextInt(2);
makeWhatzit(choice, whoozit);
}
private void makeWhatzit(int num, Whoozit append)
{
if (num == 0)
{
whatzit += "d";
}
else
{
whatzit += "z";
}
whatzit += append;
}
public String toString()
{
return whatzit;
}
}
//CLASS BLURB
import java.util.Random;
public class Blurb
{
private int num;
private Whoozit who;
private Whatzit what;
private Random rand;
private String blurb;
public Blurb()
{
who = new Whoozit();
what = new Whatzit();
rand = new Random();
num = rand.nextInt(100);
makeBlurb(who, what, num);
}
private void makeBlurb(Whoozit whos, Whatzit whats, int iterations)
{
blurb = whos.toString();
for(int counter = 0; counter < iterations; counter++)
{
blurb += whats.toString();
whats = new Whatzit();
}
}
public String toString()
{
return blurb;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.