Pages

Saturday, June 1, 2013

Banking Accounts Class !


class checkingAccount
{
 public $balance = 0;  //our defined variable set at zero//

 public function showBalance()
 {
   return 'Balance: ' .$this->balance;
 }//end function showBalance//

 public function withdrawFunds($amount)
 {
   if (($this->balance)<$amount)
   {
    echo 'Insufficient Funds.<br />';
   } else {
    $this->balance = $this->balance - $amount;
   }//end if balance
 }//end function withdrawFunds//

 public function depositFunds($amount)
 {
  $this->balance = $this->balance + $amount;
 }//end function depositFunds//

}//end class

//WE CAN CALL THE NEW CLASS FOR A DEPOSIT ON ONE PAGE//
 $account = new checkingAccount; //we call our class//
 $account = $this->depositFunds(1500);
 echo $account->showBalance();

//OR ON ANOTHER PAGE WE CAN CALL THE CLASS FOR A WITHDRAW//

$account = new checkingAccount; //we call our class//
 $account = $this->withdrawFunds(500); //we set our amount of deposit//
 echo $account->showBalance();

//OR WE CAN DO BOTH ALLOWING THE MATH FROM BOTH TO BE CALCULATED AT ONCE//
//ON A NOTHER PAGE//
$account = new checkingAccount; //we call our class//
$account = $this->depositFunds(1500);
 $account = $this->withdrawFunds(500); //we set our amount of deposit//
 echo $account->showBalance(); //balance will output 1000 answer//

No comments:

Post a Comment