To start, here are two compiled Java programs:
Lab6.jar and Plotter.jar.
Download them now to your lab6 directory and run:
java -jar Lab6.jar
Press Ctrl-c in the terminal to stop the program.
In the output you will see a list of coordinates followed by an 'r' or 'b'.
The program is outputting row, column, and a color code for moving dots:
19 70 r ← round n, red dot at row=19, col=70 76 1 b ← round n, blue dot at row=76, col=1 done 19 69 r ← round n+1, red dot at row=19, col=69 76 2 b ← round n+1, blue dot at row=76, col=2 done ...
Did you get an error like java.lang.UnsupportedClassVersionError?
If so, it's because the javac version used to compile the code in Lab6.jar or Plotter.jar is newer than what's on your VM. Update your VM by running the following commands from your terminal:
sudo apt update sudo apt upgrade -y
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 -jar Lab6.jar | java -jar Plotter.jar
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. The output that follows will be values for the next "round".
So what do you have to do? Well, even though you can't see the source code, the program Lab6 is written entirely as a Procedural Program. You will write it as an Object-Oriented Program using proper Encapsulation, Data Hiding, Inheritance, and Polymorphism! Once done, you will add some customized Dots to the program as well.
You don't have to look now, but at some point you'll want to read the documentation for these classes:
Dot Documentation
MovingDotList Documentation
You can look at but, do not alter Lab06.java until you complete Steps 1 & 2. It will not compile until you create the missing classes that it needs.
Feel free to look, run, and play with DotTest.java all you want. It is provided so that you can see an example of the Dot class in use and to provide context for how Dot positions map to the Plotter.
java DotTest | java -jar Plotter.jar
It's time to practice your inheritance skills again! Using the Dot class as the base/parent class, define a new class called MovingDot.
What's a MovingDot? - Well that's simply a Dot that moves in a direction.
What fields should it have? - That's for you to figure out!
What methods should it have? - That's for you to figure out, too, except your MovingDot must have at least the following:
// a constructor that takes row and column position as integers
public MovingDot(int r, int c){ ... }
// a step method that moves the Dot in the direction that it is facing
public void step(){ ... }
The rest is up to you!
Exception!
There is one important rule that you must follow:
MovingDot is NOT ALLOWED to have a field for or deal with color in any way!
Not as a field and not as a parameter into any methods!
Be warned, the penalty for breaking this rule will be stiff!
Practice your inheritance skills ... AGAIN! This time, using the MovingDot class as the base/parent class, define two new class called RedDot and BlueDot.
What's a RedDot? - Well that's simply a MovingDot that's the color red and which randomly choses left, right, or straight at every step.
What's a BlueDot? - Well that's simply a MovingDot that's the color blue and which randomly choses left, right, or straight at every 10th step.
What methods do you need? - You've got to figure this out too, but this is where polymorphism starts to take part in your program. Go back and review the Polymorphism lecture if you need to.
Another Rule!
RedDot and BlueDot are NOT ALLOWED to have a field for color!
Be warned, don't break this rule either!
Once you have your RedDot and BlueDot classes defined, you will now be able to compile and run the original Lab06.java file you downloaded during Step 0.
When you go to run your program, you won't be using Lab6.jar, but the resulting ouput should look the same as if you did. You will use the following:
java Lab06 | java -jar Plotter.jar
Create a README file and write a paragraph that explains how your design makes use of encapsulation, information hiding, inheritance, and polymorphism.
Now that you have a nice object-oriented version running that mimics the original, your next step is to add third type of MovingDot called GreenDot. What exactly it does is up to you, but it needs to use some diagonal motion and it must be green. The principal thing to keep in mind is how OOP makes this easier and cleaner. You must ensure that Lab06 still works the same as before, even after you've added your new GreenDot.
Ugh! All these stinking Rules!
Just like RedDot and BlueDot...
GreenDot is NOT ALLOWED to have a field for color!
Create yet another type of MovingDot, 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 Dot that draws letters!
Here are all of the color choices for Dots:
~/bin/submit -c=IC211 -p=Lab06 *.java README