Set: Wednesday
3rd
April 2019
Due: Monday 15th
April 2019 at
or before midnight
|
|
This assignment involves adding some
functionality to the "Box" objects that I'm providing for
you in the box
module.
Your task is to create a "dance" with two boxes, Alice
and Bob. This means that the two boxes should respond to
each other's motions. For example, if Alice moves right,
Bob might move left; if Alice moves towards Bob, Bob
should move towards Alice. I'm deliberately leaving the
details of this up to you. The movements "dancers" of one
of the could be controlled by mouse movements, or by
pseudo-random numbers, or by keystrokes; the second
"dancer" should move in response to the first.
You should create a new subclass of box
called dancingBox . This does not mean
that all of your code should go in dancingBox ;
you may well discover that some basic functionality of a box
is missing from the box class, in which case
you should add it there. You should place box
responsibilities in box , and dance
responsibilities in dancingBox .
Start the dance by making a request like:
alice.danceWith(bob)
Pair Programming
As mentioned in class, this work can be very rewarding
(and certainly easier) if done in pairs. I recommend this
strongly, although it’s not strictly required.
Pairs can be arranged using Piazza. If you pair, make sure
that both partners get to "drive" (write code), and both
partners get to "navigate" (think about where you are
going). Put a post on Piazza to
"Instructors" with the names of the students in your
"pair" as soon as it is set up, so that I can create a D2L
group for you.
Submitting
When you are done, upload your grace modules to the D2L
assignment dropbox that I will create for this
purpose. Be sure to include instructions for
starting and controlling your dance as a note in
D2L. (You can put that information as a comment in
your modules too, but then I'll need to know where to
look!) If you have a partner, upload the code only
once; if you have published the names of your pair on
Piazza, I will have created a “group” for you in
D2L.
Hints
- Try to get familiar with using the Grace Web
Environment, before next Wednesday, 10th
April. I'll dedicate some time in class to getting
you ‘unstuck’.
- There is a pseudo-random number method in the random
module.
- You will find Grace Resources on the “Resources” page
of the Piazza site.
- Keep a notebook. As you figure stuff out, write it
down, so that you don’t have to figure it out more than
once. Consider whether you might post your notes on
Piazza — will they help other students, “giving the game
away”
- Here is what we learned from previous versions of this
assignment:
1. Don't email code from yahoo.com!
2. Size of Methods <= 10 lines
3. If you have a non-trivial algorithm, explain it.
- Use Explaining variable names (Beck
p. 108)
- Use Intention-revealing selectors
for method names (Beck p. 49)
- If all else fails, use a comment! But
first read Method Comment (Beck p. 40).
4. Methods should (usually) either DO
something or ANSWER a
value, but not both. This is not a firm rule,
but a useful guideline. The main exceptions are object
mutators like add and
at(_)put(_), which, by
convention, have the effect of changing the object, but
which also answer the object that was changed.
5. As a consequence of the above, accessor methods
usually should not have side effects!
6. Follow the directions for the assignment
7. Hand in on time.
8. Start the selectors of Boolean attributes with some
form of the verb to be, such as "is" or "has".
For example: bob.isReady , alice.hasPartner
9. Use module-level methods when appropriate.
10. Classes (methods that create objects) can have any
name that is meaningful. They are not restricted to
being called new ; my class for creating
boxes has a factory method called named(_) that
takes the name of the to-be-created object as its
argument.
How to get Started
- Start now. You will get stuck. Allow
time to get unstuck.
- Look at the grading rubric (pdf, rtf) so that you know
what criteria we will be grading on.
- Start by loading the box module that I wrote.
- Implement a method
dance
(which should make the receiver do a solo dance). Try it
out.
- Implement
danceWith(anotherBox )
(which makes the receiver dance with anotherBox ).
danceWith(_) will
require that you add an instance variable to box ,
so that a box can remember its partner.
- It’s OK to start by modifying the existing
classes; you can refactor the code to move the
appropriate behaviour into your own
dancingBox
class later. Or you can start by creating a dancingBox
as a subobject of box .
Don't Panic
I'm aware that I'm throwing you in to the "deep end of
the pool" with this assignment. This is partly because I
don't have all the resources that I would like at hand,
and partly because a good way to "get" OOP is to struggle
with it. However, you are in a safe environment. There are
plenty of life preservers available, in the form of books
and web resources, and there are people to help: your
classmates, and your instructor. I expect that you
will get stuck. There will be time in the next class
session (Wednesday 10th) for getting you
“unstuck”. So, come to class armed with questions.
Don't expect to solve this the night before it is due.
Also, be aware that there is nothing “golden” about the box
module that I wrote. It's probably not very good, and it’s
certainly buggy. It's based on someone else's code
that interacts with the DOM of the web browser, which you
may well know more about than I do.
|