Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class ATM
- {
- private $money = array("100r" => 0,
- "500r" => 0,
- "1000r" => 0,
- "5000r" => 0);
- private $defmoney = array("100r" => 0,
- "500r" => 0,
- "1000r" => 0,
- "5000r" => 0);
- public function initatm(int $m100r, int $m500r, int $m1000r, int $m5000r)
- {
- $this->money["100r"] = $m100r;
- $this->money["500r"] = $m500r;
- $this->money["1000r"] = $m1000r;
- $this->money["5000r"] = $m5000r;
- $this->defmoney["100r"] = $m100r;
- $this->defmoney["500r"] = $m500r;
- $this->defmoney["1000r"] = $m1000r;
- $this->defmoney["5000r"] = $m5000r;
- }
- public function resetatm()
- {
- $this->money["100r"] = $this->defmoney["100r"];
- $this->money["500r"] = $this->defmoney["500r"];
- $this->money["1000r"] = $this->defmoney["1000r"];
- $this->money["5000r"] = $this->defmoney["5000r"];
- }
- public function moneycount()
- {
- return ($this->money["100r"]*100 + $this->money["500r"]*500 + $this->money["1000r"]*1000 + $this->money["5000r"]*5000);
- }
- public function addmoney(int $m100r, int $m500r, int $m1000r, int $m5000r)
- {
- $this->money["100r"] = $this->money["100r"] + $m100r;
- $this->money["500r"] = $this->money["500r"] + $m500r;
- $this->money["1000r"] = $this->money["1000r"] + $m1000r;
- $this->money["5000r"] = $this->money["5000r"] + $m5000r;
- }
- public function givemoney(int $count)
- {
- if ($count <= $this->moneycount()) {
- if ($count % 100 == 0)
- {
- if ($count >= 5000) {
- $this->money["5000r"] = $this->money["5000r"] - (int)$count / 5000;
- $count = $count % 5000;
- $this->money["1000r"] = $this->money["1000r"] - (int)$count / 1000;
- $count = $count % 1000;
- $this->money["500r"] = $this->money["500r"] - (int)$count / 500;
- $count = $count % 500;
- $this->money["100r"] = $this->money["100r"] - (int)$count / 100;
- }
- elseif ($count >= 1000) {
- $this->money["1000r"] = $this->money["1000r"] - (int)$count / 1000;
- $count = $count % 1000;
- $this->money["500r"] = $this->money["500r"] - (int)$count / 500;
- $count = $count % 500;
- $this->money["100r"] = $this->money["100r"] - (int)$count / 100;
- }
- elseif ($count >= 500) {
- $this->money["500r"] = $this->money["500r"] - (int)$count / 500;
- $count = $count % 500;
- $this->money["100r"] = $this->money["100r"] - (int)$count / 100;
- }
- else {
- $this->money["100r"] = $this->money["100r"] - (int)$count / 100;
- }
- } else {
- echo 'The amount must be a multiple of 100';
- }
- } else {
- echo 'Insufficient funds in the ATM';
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement