Answer the question
In order to leave comments, you need to log in
Implement the remove method in the Cart class to remove products. The method should take as a parameter the name of the product to be removed?
I don’t understand how to pass the name of the product to the remove() method , for which there is a getter in the Product class
Here is my code:
class Product
{
private $title;
private $price;
private $quantity;
public function __construct($title,$price,$quantity) {
$this->title = $title;
$this->price = $price;
$this->quantity = $quantity;
}
public function getProductTitle() { return $this->title; }
public function getProductPrice() { return $this->price; }
public function getProductQuantity() { return $this->quantity; }
public function getCost() {
return $this->price * $this->quantity;
}
}
class Cart
{
private $products = [];
public function addProduct(Product $product) {
$this->products[] = $product;
}
public function removeProduct() {
//
}
Answer the question
In order to leave comments, you need to log in
There is no trick here
public function removeProduct(string $productName) {
//
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question