<?php /* * Run in command line: php test.cash.machine.php */ require_once "cash.machine.php"; print "\nInput: 30\n"; print_r(CashMachine::getBillsOfAmount(30)); print "\nInput: 80\n"; print_r(CashMachine::getBillsOfAmount(80)); print "\nInput: Null\n"; print_r(CashMachine::getBillsOfAmount(null)); try { print "\nInput: -130\n"; print_r(CashMachine::getBillsOfAmount(-130)); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } try { print "\nInput: 125\n"; print_r(CashMachine::getBillsOfAmount(125)); } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; }
for ($i = 0; $i < count($notes); $i++) { if ($notes[$i] < $amount || $notes[$i] == $amount) { $count[$i] = floor($amount / $notes[$i]); $amount = $amount % $notes[$i]; } } /* * Composition of which and how many notes will be used to serve */ if ($amount == 0) { for ($i = 0; $i < count($count); $i++) { if ($count[$i] != 0) { echo $notes[$i] . ' * ' . +$count[$i] . '=' . $notes[$i] * $count[$i] . '<br>'; $tot += $notes[$i] * $count[$i]; } } } else { if ($amount < 0) { print '<b>This amount is negative and invalid to execute a withdrawal: ' . $amount . '</b>'; throw new NoteUnavailableException("Withdrawals Invalid", "This amount is negative and invalid to execute a withdrawal"); } else { print '<b>Were sorry, this machine makes no withdrawals from fewer broken values: ' . $amount . '</b>'; throw new InvalidArgumentException('Were sorry, this machine makes no withdrawals from fewer broken values : ' . $amount); } } } } // Test drive $c = new CashMachine(); print '<b>Composition and arrangement of notes for withdrawal : </b><br>'; $c->getMoney(120);
<?php require 'CashMachine.php'; $teste = new CashMachine(); $result_0 = $teste->execute(30.0); $result_1 = $teste->execute(80.0); $result_2 = $teste->execute(125.0); $result_3 = $teste->execute(-130.0); $result_4 = $teste->execute(NULL); ?> <!DOCTYPE HTML> <html> <head></head> <body> <h1>Group By Interval</h1> <p class="input_0"><?php echo $result_0; ?> </p> <p class="input_1"><?php echo $result_1; ?> </p> <p class="input_2"><?php echo $result_2; ?> </p> <p class="input_3"><?php echo $result_3; ?>