public function getGender() { if ($this->gender) { return $this->gender; } else { throw new Exception("Empty value found for gender"); } } public function __construct($name, $brand, $price, $type, $size, $color, $gender) { parent::__construct($name, $brand, $price); $this->size = $size; $this->type = $type; $this->color = $color; $this->gender = $gender; } public function provideDescriptionForProductType() { try { return "This is an article of clothing. It is a " . $this->getBrand() . " " . $this->getColor() . " " . $this->getGender() . " " . $this->getType() . " of size " . $this->getSize() . " it costs " . $this->getPrice(); } catch (Exception $e) { echo $e->getMessage(); } } } $shirt = new Clothing("Button Down Shirt", "J Peterman", '29.88', "shirt", "medium", "red", "male"); echo $shirt->provideDescriptionForProductType(); ?> </p> </body> </html>
} } class Clothing extends Product { protected $size; protected $type; protected $color; protected $gender; public function __construct($name, $brand, $price, $type, $size, $color, $gender) { parent::__construct($name, $brand, $price); $this->size = $size; $this->type = $type; $this->color = $color; $this->gender = $gender; } public function provideDescriptionForProductType() { return "This is an article of clothing. It is a " . $this->brand . " " . $this->color . " " . $this->gender . " " . $this->type . " of size " . $this->size . " it costs " . $this->price; } } $buttonDownShirt = new Clothing("Button Down Shirt", "J Peterman", 29.88, "shirt", "medium", "Eye-piercingly bright red", "Male"); $kramericaTV = new Television("Giant TV", "Kramerica", 3900.9, "LED", "100in"); echo $buttonDownShirt->provideDescription(); echo "</br>"; echo $kramericaTV->provideDescription(); ?> </p> </body> </html>