Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LANGUAGE: PHP Your method should return a string that contains the account's name and balance separated by a comma and space. For example, if an

LANGUAGE: PHP

Your method should return a string that contains the account's name and balance separated by a comma and space. For example, if an account object named ben has the name "Benson" and a balance of 17.25, the call of ben.show_user_name_and_balance() should return:

Benson, $17.25

There are some special cases you should handle. If the balance is negative, put the - sign before the dollar sign. Also, always display the cents as a two-digit number. For example, if the same object had a balance of -17.5, your method should return:

Benson, $17.50

This is what I have:

class BankAccount { private string $name; private float $balance;

public function __construct(string $name, float $balance) { $this->name = $name; if($balance > 0.0){ $this->balance = $balance; } }

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

public function getBalance(): float { return sprintf("%01.2f", $this->balance); }

function show_user_name_and_balance() { echo "{$this->getName()}, \${$this->getBalance()} "; }

}

$bank = new BankAccount('Bob', 21.764); echo $bank->show_user_name_and_balance();

?>

I dont know how too return negative number, if its negative, and if i enter 21.3. It doesnt return 21.30, But if i make 21,356 it returns 21,36

thank you :)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions