Lab #6 (The Great Dot Chase)

NOTE: You MUST include a file README (which documents your thoughts on this lab).

This lab is quite simple. I'm giving you a compiled Java program Plotter.jar, and the source code for a program Lab6.java. Download them now to your lab L06/ directory. Compile Lab6.java and run it:

java Lab6

You'll have to control-c the program to stop it. Look closely at the output and you will see a list of coordinates and r/b characters. This program is outputting 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
...

See an error? (java.lang.UnsupportedClassVersionError) It's because this library we gave you was compiled with a newer javac than what's on your VM. You can update your JDK by running the following 3 commands from your terminal:

sudo apt update
sudo apt remove oracle-java8-installer oracle-java8-set-default
sudo apt install default-jdk

A list of coordinates is pretty boring, so we also provided you a Plotter program that reads coordinates from STDIN and plots them for a nice little visual of moving dots. Try it out yourself:

java Lab6 | java -cp Plotter.jar Plotter

The output of Lab6 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", so now the updated display should be shown, and what follows will be values for the next "round".

So what do you have to do? Well, the program Lab6 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.

Colors

Here are your color choices as you make your things: r (red), b (blue), g (green), y (yellow), o (orange), p (pink), m (magenta), k (black)

Step 1

Rewrite Lab6 as an object-oriented program. You will (presumably) be creating other .java files as well. The output of Lab6 should not change, but the design must follow all the good object-oriented design principles we have discussed. In particular, you must use encapsulation, information hiding, inheritance, and polymorphism. Maximize code reuse; keep implementation and interface as separate as possible. Your inheritance should follow the picture on the right.

You must do these things:

  1. Remove static methods: only main() should be static in all of your classes.
  2. Polymorphism: Your parent class Thing most likely will not need a single if statement. If you find you need one/more, make sure there isn't a way to utilize polymorphism instead. If you still find the need for if statements, ask your instructor if they are appropriate. Related to this, your child classes should have at least one method which demonstrates polymorphism. This should naturally come from your design, but we make note of it here as a requirement to give you that extra nudge.
  3. Use a linked list: Remove Node from main() and put it inside a proper List or Queue class. You'll have to write this, or adapt a queue from previous assignments/labs. Your main() should not have Node variables anymore, but instead a List or Queue variable with nice calls such as list.add(thing)
  4. Show Instructor: Show your design and code to your instructor and describe how your new implementation follows object-oriented principles before you move on to part 2,
  5. README: Create a README file and write a paragraph that explains how your redesign makes use of encapsulation, information hiding, inheritance and polymorphism.

Step 2

The original Lab6 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. Ensure that Lab6 still works the same as before, even after you've added your new type of Thing.
  2. Add a paragraph to the README file that explains how your new OOP design makes adding new types of Things easy.
  3. 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.

Extra Credit

(optional) Create yet another type of movable thing, follow proper OOP design, and have it move in a more complicated way. Points will be given for creativity and complexity. As an example, imagine coding a thing that draws letters!

Submission

  1. Submit your source code via the submit system:
    ~/bin/submit -c=IC211 -p=Lab06 *.java README
  2. There are no automated tests. We will run your programs ourselves manually. This means you must thoroughly test your code yourself!. Many points will be lost if code does not compile or run.
  3. Be prepared to demonstrate your program at the beginning of the next lab period.