Overview

This program is to be done in pairs. Once again, it will be you and your partner working at the same keyboard. I expect you both to contribute equally to the solution. In particular, take turns being the one typeing. You MUST include a file README (all in uppercase, no .txt at the end!) in your submission giving the names and alphas of both partners.

This lab is quite simple. I'm giving you a compiled Java program Plotter.jar, and the source code for a program Lab07a.java. Download them now with the commands:

curl -O http://www.usna.edu/Users/cs/wcbrown/courses/S15IC211/lab/l07/Plotter.jar
curl -O http://www.usna.edu/Users/cs/wcbrown/courses/S15IC211/lab/l07/Lab07a.java
Compile Lab07a.java and run it like this:
java Lab07a | java -cp Plotter.jar Plotter
... you'll see a cool little visual. The gist is that Lab07a (which you can run on your own, by the way) outputs row, column and color (r=red, b=blue, g=green, o=orange, y=yellow, m=magenta, p=pink) for moving dots.
19 70 r ← round x, red  dot at row=19, col=70
76 1 b  ← round x, blue dot at row=76, col=1
done
19 69 r ← round x+1, red  dot at row=19, col=69
76 2 b  ← round x+1, blue dot at row=76, col=2
done
...
If you run it as instructed, the output of Lab07a is piped into Plotter, which plots each of the dots at the row,col coordinates and color given. The "done" at the end of a group of lines tells us that we are done with the "round", and what follows will be values for the next "round".

So what do you have to do? Well, the program Lab07a is written entirely as a Procedural Program. You will re-write it as an Object-Oriented Program, and once done, you will extend its functionality a bit as well.

Step 1

Rewrite Lab07a as an object oriented program. The driver file will be Lab07b.java, and you will (presumably) be creating other .java files as well. The output of Lab07b should be just like Lab07a, but the design must follow all the good object oriented design principles we have discussed. In particular, you must use encapsulation and information hiding, inheritance and polymorphism. Maximize code reuse, keep implmentation and interface as separate as possible.

You must do two things:

  1. Show your code to your prof and describe how your new implementation follows object-oriented principles before you move on to part 2,
  2. Add a paragraph to the README file that explains how your redesign makes use of encapsulation, information hiding, inheritance and polymorphism.

Step 2

The original Lab07a had two types of Things: typeA, which randomly choses left, right or straight at every round; and typeB, which randomly chooses left, right or straight every 10th round. Now that you have a nice object-oriented version, I want you to add a third type of Thing. What exactly it does is up to you, but it needs to use some diagonal motion (i.e. left-right-left-right-... sequences). The principal thing to keep in mind is how OOP makes this easier and cleaner. You must
  1. Make a new driver file Lab07c.java for this program.
  2. Ensure that Lab07b still works the same as before, even after you've added your new type of Thing to Lab07c.
  3. Add a paragraph to the README file that explains how your new OOP design makes adding new types of Things easy.
  4. Add a final paragraph to the README that explains exactly where in your program there is a polymorphic function call, and how that plays an essential role in the program functioning properly.

Submitting the lab

You need to submit this properly. We won't track down your missing pieces or your otherwise improperly submitted labs. Here's all you need to do. Cd to the directory in which your lab files lie, and give this command:
ic211-submit lab07 README *.java *.jar