Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a php class that implements a bank account for deposits and withdrawals. T

ID: 3704378 • Letter: W

Question

Write a php class that implements a bank account for deposits and withdrawals. This class will have data members representing name and balance. It will also have a constructor that takes a name parameter and sets the name data member accordingly. Create functions for getbalance and getname. Create a function for deposit that will check if deposit amount is positive and if so add it to the account. Create a function for withdraw that will check if the withdraw amount is positive and if the it is less then the account balance and if so withdraw it. Lastly create a_ tostring method that will print out the account details when the object is used in an expression block. Create client code that includes this class. Create 2 bank account objects with it. Give the first account the name ica, deposit 5, withdraw 1.25, and withdraw 1000. Create a second account with the name tin, deposit 999 and deposit-15. Then display both accounts in a div in html.

Explanation / Answer

here is your program : ---------->>>>>>>>>>

<?php
class BankAccount{
  var $name;
  var $balance;

  function __construct($n){
   $this->name = $n;
   $this->balance = 0.0;
  }

  public function getBalance()
  {
   return $this->balance;
  }

  public function getName(){
   return $this->name;
  }

  public function deposit($Amount)
  {
   # code...
   if($Amount > 0){
    $this->balance = $this->balance + $Amount;
   }
  }

  public function withdraw($Amount){
   if($Amount > 0 && $Amount <= $this->balance){
    $this->balance = $this->balance - $Amount;
   }
  }

  public function __toString(){
   return "Customer = ".$this->name." Balanace = ".$this->balance;
  }
}

$bank1 = new BankAccount("Dhananjay");
$bank2 = new BankAccount("Rahul");
$bank1->deposit(5);
$bank1->withdraw(1.25);
$bank1->withdraw(1000);


$bank2->deposit(999);
$bank2->withdraw(-15);
?>
<!DOCTYPE html>
<html>
<head>
  <title>Display Bank Balance </title>
</head>
<body>
  <div>
   <p><?php echo $bank1 ?></p>
   <p><?php echo $bank2 ?></p>
  </div>
</body>
</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote