Add exams from exam156 to exam199
This commit is contained in:
43
exam196/index.php
Normal file
43
exam196/index.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
class BankAccount
|
||||
{
|
||||
// modifikatori vidljivosti u PHP public, protected, private
|
||||
public $balance = 0;
|
||||
|
||||
public function DisplayBalance()
|
||||
{
|
||||
return 'Balance: ' . $this->balance . '<br>'; // Ovako pristupamo vrednosti balance 'pravimo referencu'
|
||||
}
|
||||
|
||||
public function Withdraw($amount)
|
||||
{
|
||||
if ($this->balance < $amount) {
|
||||
echo 'Not enough money <br> ';
|
||||
} else {
|
||||
$this->balance = $this->balance - $amount;
|
||||
}
|
||||
}
|
||||
|
||||
public function Deposit($amount){
|
||||
$this->balance = $this->balance + $amount;
|
||||
}
|
||||
}
|
||||
|
||||
//Multiple instances of class :
|
||||
$alex = new BankAccount;
|
||||
$billy = new BankAccount;
|
||||
|
||||
$alex -> Deposit(100);
|
||||
$billy -> Deposit(50);
|
||||
|
||||
$alex -> Withdraw(98);
|
||||
$billy -> Withdraw(12.5);
|
||||
|
||||
echo $alex -> DisplayBalance();
|
||||
echo $billy -> DisplayBalance();
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user