package { // The actionscript_zoo_lib_Apple class represents one of the types of food a pet can eat public class actionscript_zoo_lib_Apple extends actionscript_zoo_lib_Food { // The amount of calories in an actionscript_zoo_lib_Apple object, if no specific // amount is indicated private static var DEFAULT_CALORIES:int = 100; // Tracks whether an actionscript_zoo_lib_Apple object has a worm private var wormInactionscript_zoo_lib_Apple:Boolean; // Constructor public function actionscript_zoo_lib_Apple (initialCalories:int = 0) { // If no valid calorie amount is specified... if (initialCalories <= 0) { // ...give this actionscript_zoo_lib_Apple object the default amount initialCalories = actionscript_zoo_lib_Apple.DEFAULT_CALORIES; } // Invoke the Food class constructor super(initialCalories); // Randomly determine whether this actionscript_zoo_lib_Apple object as a worm (50% chance) wormInactionscript_zoo_lib_Apple = Math.random() >= .5; // Give this food item a name setName("actionscript_zoo_lib_Apple"); } // Returns a Boolean indicating whether the actionscript_zoo_lib_Apple object has a worm public function hasWorm ():Boolean { return wormInactionscript_zoo_lib_Apple; } } }