Need to import ArrayList
Description of a park:
(1) a park has:
- a bunch of balloons (ArrayList)
- a bunch of flowers (ArrayList)
(2) a park can be created:
- by specifying nothing, but
creating empty storage
for the balloons and flowers
(3) a park can do:
- receive a single balloon and
add it to its set of balloons
- ask all balloons to move a bit
estimate wind speed
get i-th balloon
ask i-th balloon to
move and draw itself
|
package cs1.ParkApp;
import cs1.app.*;
import java.util.ArrayList;
public class Park
{
// the features (data members)
private ArrayList<Balloon> balloonsList;
// private ArrayList<Flower> flowersList;
// the constructor(s)
public Park()
{
balloonsList = new ArrayList<Balloon>(); // make empty set of balloons
// flowersList = new ArrayList<Flower>(); // make empty set of flowers
}
// the behaviors (methods)
public void add( Balloon balloon )
{
balloonsList.add( balloon );
}
public void driftBalloons( )
{
for ( int i = 0 ; i < balloonsList.size() ; i++ )
{
double dx = canvas.getRandomDouble( -3, 3 );
double dy = -1;
Balloon balloon = balloonsList.get( i );
balloon.drift( dx, dy );
balloon.draw();
}
}
}
|