Code
<?php
class Account
{
private $balance;
/**
- initial amount
- @param int $initialAmount
*/
public function __construct($initialAmount)
{
if($initialAmount<0)
{
echo "The initial balance was invalid";
$this->balance=0;
}
else
$this->balance = $initialAmount;
}
/**
- deposit money to the bank account
- @param int $amount amount to deposit
*/
public function deposit($amount){
$this->balance += $amount;
}
public function withdraw($amount)
{
if($amount > $this->balance)
echo"Debit amount exceeded account balance";
else
$this->balance -= $amount;
}
/**
- returns balance
- Return int balance
*/
public function getBalance(){
return $this->balance;
}
}
$account1 = new Account(1000);
$account2 = new Account(-100);
echo sprintf("Initial balance of the accout1 is %0.2f.<br/>",$account1->getBalance());
echo sprintf("Initial balance of the accout2 is %0.2f.<br/>",$account2->getBalance());
echo sprintf("</br>Deposit $2000 to the bank account1.<br/>");
$account1->deposit(2000);
echo sprintf("Total balance of the account1 is $%0.2f<br/>", $account1->getBalance());
echo sprintf("</br>Deposit $3000 to the bank account1.<br/>");
$account2->deposit(3000);
echo sprintf("Total balance of account2 is $%0.2f<br/>", $account2->getBalance());
echo sprintf("</br>Withdraw $100 from the bank account1.<br/>");
$account1->withdraw(100);
echo sprintf("Total balance of account1 is $%0.2f<br/>", $account1->getBalance());
echo sprintf("</br>Withdraw $5000 from the bank account1.<br/>");
$account2->withdraw(5000);
echo sprintf("<br>Total balance of account1 is $%0.2f<br/>", $account2->getBalance());
?>
output
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.