Fall 2006, David Matuszek
The assignment asks you to keep track of "dead" frogs. However, with the assignment the way it is, all your frogs can get across the road safely. I said in lab on Friday that I would need to think some more about this.
I didn't want to ask you to make some of your frogs deliberately "stupid." Fortunately, there is a better way.
The roadway is dark gray. Dark gray cars are hard to see on it (mine are outlined in black, so it's still possible for the human to see them). So here's the new requirement: If a car is very dark--dark gray or black--the frog doesn't see it. (If you use other colors, decide which cars are dark enough to be invisible.) You should have a high enough proportion of dark cars that we can test your program easily.
There are two obvious ways to make this work in your program.
I think the second of these is clearly the better solution. Ignoring certain cars just doesn't seem like something a frog would deliberately do.
The assignment says, "When you tell a frog to move, give it (as a parameter
to your 'hop' method), the
ArrayList of all the currently active
cars." So your Frog class doesn't need to
be changed at all. Instead, go through the
ArrayList of currently
active cars and put all but the dark cars into a second
which you pass to the frog. (A car can be in more than one list at a time.) I'd
suggest writing a method in your
Frogger class with a signature like:
private static ArrayList<Car> getVisibleCars(ArrayList<Car> allCars)
This says: The method
getVisibleCars takes, as a parameter,
and returns an
Cars as its
private because there's no reason for any other class
Frogger to use it, and it's
it doesn't need an object of type
Frogger in order to do