Find and describe the explicit calls to superclass members in the ActorWorld, BoundedGrid, Bug, Rock, WorldFrame, and
Question:
Find and describe the explicit calls to superclass members in the ActorWorld, BoundedGrid, Bug, Rock, WorldFrame, and GridPanel classes, mentioned in Exercise 15, above. In each class that makes such a call, identify the class, the method or constructor that includes the call, the constructor or method that’s called, and the class in which that called member resides.
Exercise 15
GridWorld’s firstProject file contains the BugRunner driver:
BugRunner starts by creating an instance of ActorWorld named world. ActorWorld’s constructor immediately creates a 10 × 10 BoundedGrid. Next, BugRunner asks the ActorWorld object to add a new Bug at a random location, and it then adds a new Rock at a different random location. ActorWorld’s add method tells each new occupant where it is supposed to go in the grid and then tells that occupant to put itself into the grid at that location.
BugRunner’s last statement calls ActorWorld’s show method. This show method instantiates a WorldFrame (a GUI window) with an argument referring back to the ActorWorld object.
WorldFrame’s constructor instantiates a GridPanel. Then it uses its reference to the ActorWorld object to get a reference to the BoundedGrid, and it passes this BoundedGrid reference on to the new GridPanel. GridPanel’s drawOccupants method uses this BoundedGrid reference to call BoundedGrid’s getOccupiedLocations method. This allows GridPanel’s paintComponent method to put bug and rock images in their proper places each time it repaints the screen.
Provide an abbreviated UML class diagram that contains all classes identified in the above two paragraphs, except for the BugRunner class. Use appropriate composition (filled diamond) and aggregation (hollow diamond) links. Include multiplicity symbols where one of the multiplicities might be greater than 1. For the relationship between ActorWorld and WorldFrame, use a simple bidirectional association, like this:
Or use a bidirectional dependence, like this:
Step by Step Answer:
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean