- Create a class called DepositContainer and declare two private variables:
- _maxBottles (int)
- _amountOfBottles (int)
- Save it in a folder called "PET deposit" under the name "DepositContainer.as"
- Create a private function called init() and set _maxBottles to 0 and _amountOfBottles to 5
- Create getter/setter for _maxBottles and _amountOfBottles
- Create a public function called recieveBottle() that accepts an integer and updates _amountOfBottles via it's setter.
- Create a public function called emptyContainer() that sets _amountOfBottles to 0 via it's setter.
- In a Flash document, create an object called myContainer of the type DepositContainer.
- Save the Flash document in the same folder as the class.
- Recieve 13 bottles in myContainer via the recieveBottle() method and trace the amount of bottles to the output window.
- Call emptyContainer() and trace the amount of bottles again
- Modify the recieveBottle() method so it returns a boolean value.
- Use an if-statement in the recieve bottle method, to test if there is more bottles than the maximum allowed. Return true or false, depending on the outcome.
- Modify the flash document, so the true or false value is contained in a boolean called success.
- Write an if-statement that tests for success, and traces a message depending on the output.
Look at the attached file for a working file.
Classes > Variables
Get and Set Accessor methods