Skip to content

Instantly share code, notes, and snippets.

@mmenozzi
Created February 15, 2014 17:03
Show Gist options
  • Save mmenozzi/9022004 to your computer and use it in GitHub Desktop.
Save mmenozzi/9022004 to your computer and use it in GitHub Desktop.
<?php
/**
* @author Manuele Menozzi <mmenozzi@webgriffe.com>
*/
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