PET deposit 1 (Class)

  1. Create a class called DepositContainer and declare two private variables:
    • _maxBottles (int)
    • _amountOfBottles (int)
  2. Save it in a folder called "PET deposit" under the name "DepositContainer.as"
  3. Create a private function called init() and set _maxBottles to 0 and _amountOfBottles to 5
  4. Create getter/setter for _maxBottles and _amountOfBottles
  5. Create a public function called recieveBottle() that accepts an integer and updates _amountOfBottles via it's setter.
  6. Create a public function called emptyContainer() that sets _amountOfBottles to 0 via it's setter.
  7. In a Flash document, create an object called myContainer of the type DepositContainer.
  8. Save the Flash document in the same folder as the class.
  9. Recieve 13 bottles in myContainer via the recieveBottle() method and trace the amount of bottles to the output window.
  10. Call emptyContainer() and trace the amount of bottles again
  11. Modify the recieveBottle() method so it returns a boolean value.
  12. 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.
  13. Modify the flash document, so the true or false value is contained in a boolean called success.
  14. 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.

Reference

Classes > Variables

Get and Set Accessor methods

Conditionals

if

 

 

Attachment: