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.
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)
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:
list.add(thing)
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
(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!
~/bin/submit -c=IC211 -p=Lab06 *.java README