CS 161 Lab C - The Ventriloquist

Due Fri Sep 20 at 9:00am

Overview

In this lab, you will be implementing a program to create a simple Ventriloquist routine. The routine will be performed in the console: that is, actions will be printed out as text. Your routine might look something like this:

Introducing: Jack and the amazing Alice
Jack says 'Hello'
Alice says 'Hello yourself!'
Jack says 'That isn't very nice'
Alice wiggles her ears
Jack says 'What to see a trick?'
Alice says 'Sure!'
Jack starts chugging a glass of water
Alice says 'And his lips aren't even moving!'
Jack stops chugging a glass of water
Jack says 'Ta da!'

Jack puts down Alice and picks up Bob
Jack says 'Hello'
Bob says 'Hello yourself!'
Jack says 'That isn't very nice'
Bob says 'I don't care!'
Bob sticks out his tongue
Jack says 'You're mean, and I'm changing your name to mud'
Mud says 'Phooey'

You are of course welcome to modify the exact details of the routine, as long as you meet the requirements described below. Your routine will utilize two new classes that you will create: a Ventriloquist class and a Dummy class (to represent the puppet).

Remember that this lab should be completed in pairs. You will need to find a different partner than you had for the last lab. Be sure to review the pair programming guidelines before you begin; remember to switch off who is driving and who is navigating!

Objectives

Necessary Files

You will be creating your own program from scratch for this assignment---select "Project > New Project" from the BlueJ menu to create a new project.

Assignment Details

For this program, you will need to create three (yes, 3!) new classes: Ventriloquist, Dummy, and VentriloquistRoutine. The first two of these are object classes--that is, they are classes intended to be instantiated as objects. The last is a main or tester class--that is, it just has a main() method and runs a program that uses the other two classes.

The individual classes are detailed below; you should read through the whole assignment to get a sense for how things fit together. You will want to be developing your VentriloquistRoutine class at the same time you are developing the other two classes!

Dummy

The first class you should create is the Dummy class. This is the easiest of the classes to make. As you read the requirements, think about what attributes and method signatures the class will have!

  1. Each Dummy will need to have a name.
  2. Each Dummy also has a button hidden at the bottom that performs a specialAction. In the example above, Alice's button "wiggles her ears", and Bob's button "sticks out his tongue." These actions are written as Strings, and should be remembered (hint: as an instance variable!) by each Dummy object.
  3. Your Dummy class will need to have a constructor that takes in the name and special action (whenever you construct/instantiate a Dummy, you give it a name and specify what the button does!)
  4. Your Dummy class should have a getter and setter for the name--that way you can ask the Dummy what its name is, and change the Dummy's name later!
  5. Your class should also have a doSpecialAction() method. This method "performs" the special action--it does this by printing out that the Dummy has done the action. For example:
    Alice wiggles her ears
    Would show that the Dummy named "Alice" has performed the "wiggles her ears" action.

Be sure to test your Dummy class as you write it--make sure you can instantiate a Dummy, call methods on it, and that everything works the way you want!

Ventriloquist

The Ventriloquist is more complex, but not by much (it just has more methods!) As you write the methods, think about their signature: do they need any parameters? Do they need to return any values?

  1. Each Ventriloquist will need to have a name.
  2. In addition each Ventriloquist will need to have a Dummy object--the puppet it is currently using! This Object should be stored as an instance variable; remember that Objects have a dataType that is the same as their class name (so a puppet variable may have a dataType of Dummy).
  3. Your Ventriloquist class will need to have a constructor. Your constructor should take in the name of the ventriloquist.
    • Watch Out: Because Ventriloquists aren't created with a Dummy, it is possible that the box for the Ventriloquist's Dummy instance variable will be empty. In computer science, we say that an empty variable does contain a value, a special value called null.

      If you try and call a method on the value inside an empty box (so you try and tell the Dummy to do something, when there is no Dummy in the box), you will get what is called a NullPointerException--you've pointed at null and told it to do something, and null can't do anything (because it is nothing!). If you get this error, make sure that you've put a value in the variable before you call a method on that variable!

      This is a new concept and can be confusing. Please let me know if you have any problems or need help with this!

  4. Your Ventriloquist class should have a getter for its name (but no setter is needed--we don't need to change the Ventriloquist's name)!
  5. It should also have a getter and setter for the Dummy instance variable--this will let you change what Dummy the ventriloquist is using. Remember that Dummy is the dataType for a Dummy object!
  6. Your Ventriloquist should also have a toString() method so you can print out the object. Printing the Ventriloquist should produce something like:
    Jack and the amazing Alice
    (where Jack is the Ventriloquist and Alice is the Dummy).

    Remember, a toString() method does not actually print anything, it just returns a String that can be printed elsewhere (like from the VentriloquistRoutine)!

  7. Your Ventriloquist should have a say method that has the ventriloquist speak. This method should take in the line that the ventriloquist will say, and then print out that it says that line. For example:
    Jack says 'Hello'

    Note that you will need to print out the quotation marks the same way you printed out a $ in your Banking program. Hint: Print out single quotes (') not double-quotes---you need to do something special to print double quotes, which we'll talk about later!

  8. Your Ventriloquist should also have a ventriloquize method that has the puppet speak a given line by printing it out. For example:
    Alice says 'Hello yourself!'

    You will need to "ask" the puppet its name in order to print that out, but otherwise this method will work much like the say method.

  9. Your Ventriloquist should have a useSpecialAction method that tells the puppet to perform its special action (that is, the Ventriloquist hits the secret button). This method should call the puppet's doSpecialAction method.
  10. Your Ventriloquist should have 3 additional methods that will allow it to do the classic trick of having the puppet talk while the ventriloquist is drinking a glass of water.

    It should have a startDrinking method that prints out that the ventriloquist has started drinking:

    Jack starts chugging a glass of water

    and a stopDrinking method that prints out that the ventriloquist has stopped drinking:

    Jack stops chugging a glass of water

    Finally, the Ventriloquist should have a drinkAndSpeak method that takes in a line to say. This method should have the ventriloquist start drinking, ventriloquize the line, and then stop drinking.

    • This method should call the previous methods you wrote! You can call a method on the current object by using
      this.myMethod(<appropriate parameters>);

That's the full list of methods! Make sure you get them all (you should have 11 in total, counting the constructor)

VentriloquistRoutine

This class is much simpler than the others: as a "tester" class, it only has a single method: the main method (just like your BankingTester class did!)

Submission

Make sure both your names are on all the classes (Dummy, Ventriloquist, and VentriloquistRoutine), and upload the entire project directory to the LabC submission folder on hedwig (see the previous lab if you need help). Only one partner needs to upload the code. Make sure you upload your work to the correct folder! The lab is due at the start of class the morning after lab.

After you have submitted your solution, log onto Moodle and submit the Lab C Partner Evaluation. Both partners need to submit evaluations.

Grading

This assignment will be graded on approximately the following criteria:

Remember that it is very easy to get partial credit, so turn in whatever you have before the lab's due date!