-
Notifications
You must be signed in to change notification settings - Fork 0
/
o8.php
35 lines (31 loc) · 1 KB
/
o8.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
class DailyAccount{
public function __construct(public $deposit){}
private $items = [];
private $total = 0;
function addItem($name, $cost){
$this->total += $cost;
if($this->total > $this->deposit){
echo "Error: You don't have enough balance.\n";
$this->total -= $cost;
return;
}
$this->items[$name] = $cost;
}
function createReport(){
echo "Initial Deposit was {$this->deposit}.\n";
foreach($this->items as $name=>$cost){
echo "{$name} - {$cost}\n";
}
echo "-----------------------------\n";
echo "Total: {$this->total}\n";
echo "Balance: ".($this->deposit - $this->total)."\n";
}
}
$dailyAccount = new DailyAccount(1500); //instantiate
$dailyAccount->addItem("Kacha Morich", 100);
$dailyAccount->addItem("Alu", 50);
$dailyAccount->addItem("Dim", 180);
$dailyAccount->addItem("Murgi", 300);
$dailyAccount->addItem("Ghee", 800);
$dailyAccount->createReport();