CS 161 Lab D - The Ventriloquist

Due Fri Feb 13 at the start of class

Overview

In this lab, you will be implementing a program to create a simple Ventriloquist routine. The routine will be performed in the BlueJ Terminal: that is, actions will be printed out as text.

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. Be sure and note where you create the project folder, so you can upload it when you're done.

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 has a single static method and runs an algorithm that instantiates and 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.

Part 1: Designing the Dummy

In class we talked briefly about a "6-Step Design Plan" (described in the textbook on page 99). This is a behavior-focused design process that we'll practice here.

Part 2: Designing the Ventriloquist

Ventriloquist

Using the 6-Step "design algorithm" described above, you should now create the Ventriloquist class. Note that the Ventriloquist is a little more complex, but not by much (it just has more methods!)

The requirements of the Ventriloquist class are described below:

  1. Each Ventriloquist has a given name. The Ventriloquist can also return its name, but it will never need to change its name (hint: it has a getter, but no setter).
  2. In addition each Ventriloquist will need to remember a Dummy object--the puppet it is currently holding! Because we want to remember this Object, it will need to 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. The Ventriloquist is able to pick up a dummy using a method called pickUpDummy(). This method will work very similarly to a setter (and should have a return type and parameter as such). However, in addition to setting the puppet, this method should print out that the ventriloquist picked up the dummy. This will be useful for testing (and for your routine later on!)
  4. 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 nametag for the Ventriloquist's Dummy instance variable won't be attached to anything. In computer science, we say that an empty variable contains a special value called null.

      If you try and call a method on the value inside an empty variable (so you try and tell the Dummy to do something, when there is no Dummy with the nametag), 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!

  5. Your Ventriloquist should also have a toString() method so you can print out the object. The method should return a value such as "Emily and the amazing Joel" (where Emily is the Ventriloquist and Joel 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)!

  6. 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:
    Ventriloquist emily = new Ventriloquist("Emily");
    emily.say("Hello World");

    Will output:

    Emily says 'Hello World'
    • Remember to include the single quotation marks when you print! These are important for the show to look good
  7. Your Ventriloquist can also make the puppet speak a given line. This method should be called ventriloquize(). This method should print out that the dummy says the given line. For example, if the ventriloquist Emily has the Dummy Joel:
    emily.ventriloquize("I'm such a dummy!");

    Will output:

    Joel says 'I'm such a dummy!'
    • This method will need to ask the Dummy for its name, and then use that to determine what to print. Remember to add in the single quotes to whatever line is being spoken!
  8. Your Ventriloquist has a way to make its Dummy use its special action (that is, the ventriloquist hits the secret button). This method should be called useSpecialAction().
    • This method should just call the appropriate method on the dummy!
  9. 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:

    Emily starts chugging a glass of water

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

    Emily 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! Remember you can call a method on the current object by using
      this.myMethod(parameters);

Part 3: Creating Your Own Routine

  1. You'll quickly find that it's a bit tedious to type all that routine into the Code Pad. So you should create a new class that will perform the routine for you automatically. Call this class VentriloquistRoutine.
  2. This class should have exactly one method:
    public void start()
  3. Inside this method, you should instantiate a Ventriloquist object ("Emily" in the above example), as well as at least two Dummy objects ("Joel" and "David" in the above example). Your ventriloquist should perform a routine similar to the one described above using these objects.
    • Make sure that the routine lets the Ventriloquist show off all its tricks: using the Dummys' special actions, doing the drinkAndSpeak trick, etc.
    • You might start by copy-and-pasting the above routine, then modifying it as desired. You must create your own routine though!
  4. Remember: The Dummy doesn't actually ever do anything--the Ventriloquist does all the work (it just looks like the dummy is doing it). In fact, you should almost never need to call a method on the Dummy objects (except possible to ask them for and change their names).

Submission

  1. Make sure both of your names are on all of the classes you've created (Ventriloquist, Dummy, and VentriloquistRoutine). If your names aren't on your assignment, we can't give you credit!
  2. Right-click on the project folder you downloaded, then:
    • If using Linux, select Compress...
    • If using Windows, select Send to and then Zip file
    • If using Mac, select Compress ... items

    This will let you take the selected folder (or files) and generate a new compressed .zip file.

  3. Navigate to the course on Moodle (Lecture Section A), (Lecture Section B). Upload your .zip file to the Lab D Submission page. Remember to click "Save Changes"! You may submit as often as you'd like before the deadline; we will grade the most recent copy.
  4. While you're on Moodle, remember to fill out the Lab D Partner Evaluation. Both partners need to submit evaluations.

Grading

This assignment will be graded out of 28 points.