Overview
Unless your instructor directs you otherwise, 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 program named
plotter, and the source code for
a program Lab07a.java.
To get started, create a directory lab07, cd into and give the command:
Compile Lab07a.java and run it like this:
java Lab07a | ./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",
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 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
If you are feeling lost about how to do this, you might want to
look at this
example problem, which
looks at a simple problem, and explores the differences between
a procedural and object-oriented solution.
Rewrite Lab07a as an object oriented program. Name your new driver file
Lab07b.java. [Note: you ought to 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:
-
Show your code to your prof and describe how your new
implementation follows object-oriented principles before you
move on to part 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
- Make a new driver file Lab07c.java for this program.
- Ensure that Lab07b still works the same as before, even
after you've added your new type of Thing to Lab07c.
-
Add a paragraph to the README file that explains how your new
OOP design makes adding new types of Things easy.
-
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:
submit -c=IC211 -p=lab07 README *.java
Your instructor may also ask you to demo the lab, so make sure to
ask about that.