<?php class CartEntry { //changing to private private $Price; private $Quantity; public function __construct($Price, $Quantity) { $this->Price = $Price; $this->Quantity = $Quantity; } public function ReturnPrice() { return $this->Price; } public function ReturnQuantity() { return $this->Quantity; } }// end class class CartContents { //Changed to private private $items = array(); public function __construct($items) { $this->items = $items; } public function ReturnItems() { return $this->items; } } // end class class Order { private $cart; private $salesTax; function __construct( float $salesTax, Array $items){ $this->salesTax = $salesTax; $this->items = $items; } function OrderTotal() { $cartTotal = 0; for ($i=0, $max=count($this->items); $i < $max; $i++) { $cartTotal += $this->items[$i]->ReturnPrice() * $this->items[$i]->ReturnQuantity(); } $cartTotal += $cartTotal * $this->salesTax; return $cartTotal; } } $entry1 = new CartEntry(1.2, 120); $entry2 = new CartEntry(2.2,200); $mycart = new CartContents([$entry1,$entry2]); $items = $mycart->ReturnItems(); $mytax = 0.2; //Items variable can be changed with mycart $myorder = new Order($mytax,$items); echo $myorder->OrderTotal();
You have javascript disabled. You will not be able to edit any code.
Value for `_results` contains invalid data `array`