$this->type = $type_input; } public function DisplayBalance() { return 'Balance: ' . $this->balance . '<br/>'; } 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; } } class SavingsAccount extends BankAccount { } $alex = new BankAccount(); $alex->SetType('18-25 Current'); $alex->Deposit(100); $alex->Withdraw(10); $alex_savings = new SavingsAccount(); $alex_savings->SetType('Super Saver'); $alex_savings->Deposit(3000); echo $alex->type . ' has ' . $alex->DisplayBalance() . '<br/>'; echo $alex_savings->type . ' has ' . $alex_savings->DisplayBalance();
<?php class BankAccount { public $balance = 0; public function DepositBalance($amount) { return $this->balance = $this->balance + $amount; } public function DisplayBalance() { return $this->balance; } public $type = '18-25'; public function SetType($input) { $this->type = $input; } } class SavingBankAccount extends BankAccount { public $type = 'Supersaver'; } $user1 = new BankAccount(); $user2 = new SavingBankAccount(); $user1->SetType('Silver'); $user1->DepositBalance(3000); $user2->DepositBalance(1000); echo $user1->type . " Has Balance: " . $user1->DisplayBalance() . "<br/>"; echo $user2->type . " Has Balance: " . $user2->DisplayBalance();