Java Reference
In-Depth Information
Figure 28.1. The
FireworkList
class provides type-specific lists for
Firework
objects.
The
Itr
class is an inner class for
FireworkList
.
The
FireworkList
class stores its objects in a regular instance of
ArrayList
. The
add()
method ensures that only
Firework
objects enter the list. For example, the
Promo
class
creates and returns a list of promotional fireworks, using a
FireworkList
object:
package com.oozinoz.fireworks;
import com.oozinoz.units.*;
public class Promo implements UnitConstants
{
public static FireworkList getPromotionalFireworks()
{
FireworkList fl = new FireworkList();
fl.add(new Sparkler("Brightful", .35));
fl.add(new Firecracker("Frightful", .19));
fl.add
(
new Rocket(
"Heightful",
33.95,
(Length) METER.times(300))
);