-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise1b.php
76 lines (46 loc) · 1.58 KB
/
exercise1b.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
//program to calculate debits and credits in an account
$obj = new account(1000);
$obj->debit(100, 'Walmart');
$obj->credit(200, 'cash deposit');
$obj->debit(500, 'Target');
$obj->debit(100, 'Sears');
$obj->credit(600, 'refund');
$obj->debit(1200, 'Kmart');
// $transactions = $obj->debit(100);
print_r($obj);
class account{
public $starting_balance;
public $current_balance;
private $transactions = array();
public function __construct($amount){
$this->starting_balance = $amount;
$this->current_balance = $amount;
}
public function debit($amount, $source){
$transaction = array();
$transaction['type'] = 'debit';
$transaction['amount'] = $amount;
$transaction['source'] = $source;
$this->transactions[] = $transaction;
$this->current_balance = $this->current_balance - $amount;
// $this->transactions[]['debit'] = $amount;
//$this->transactions[]['source'] = $source;
}
public function credit($amount, $source){
$transaction = array();
$transaction['type'] = 'credit';
$transaction['amount'] = $amount;
$transaction['source'] = $source;
$this->transactions[] = $transaction;
$this->current_balance = $this->current_balance + $amount;
// $this->transactions[]['credit'] = $amount;
//$this->transactions[]['source'] = $source;
}
public function process(){
foreach($this->transactions as $transaction);{
print_r($transaction);
}
}
}
?>