Created
February 15, 2014 17:03
-
-
Save mmenozzi/9022004 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @author Manuele Menozzi <[email protected]> | |
*/ | |
class VendingMachine | |
{ | |
private $availableItems = array('coffe' => 0.38); | |
private $credit = 0; | |
public function addCoin($coin) | |
{ | |
if (!in_array($coin, array(0.05, 0.1, 0.2, 0.5, 1, 2))) { | |
return; | |
} | |
$this->credit += $coin; | |
} | |
public function getCurrentCredit() | |
{ | |
return $this->credit; | |
} | |
public function sellItem($item) | |
{ | |
$this->credit = $this->credit - $this->availableItems[$item]; | |
} | |
public function returnCredit() | |
{ | |
$return = $this->credit; | |
$this->credit = 0; | |
return $return; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment