Advertisement
Nikita051

Untitled

Oct 13th, 2022
1,170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. <?php
  2.     class Product{
  3.         private $name;
  4.         private $price;
  5.         private $quantity;
  6.  
  7.         public function __construct($name,$price,$quantity)
  8.         {
  9.             $this -> name = $name;
  10.             $this -> price = $price;
  11.             $this -> quantity = $quantity;
  12.         }
  13.         public function getName(){
  14.             return $this -> name;
  15.         }
  16.         public function getPrice(){
  17.             return $this -> price;
  18.         }
  19.         public function getQuantity(){
  20.             return $this -> quantity;
  21.         }
  22.         public function getCost(){
  23.             return $this->price * $this -> quantity;
  24.         }
  25.     }
  26.     class Cart{
  27.         public $products = [];
  28.  
  29.         public function add($products){
  30.             $this -> products[] = $products;
  31.         }
  32.         public function remove($name_remove){
  33.  
  34.         }
  35.         public function show(){
  36.             foreach($this->products as $value){
  37.                 echo $value->getName()." ".$value->getPrice()."Р. ".$value->getQuantity()." штук</br>";
  38.             }
  39.         }
  40.     }
  41.     $cart = new Cart;
  42.     $cart -> add(new Product("Макароны",60,30));
  43.     $cart -> add(new Product("Сосиски",200,40));
  44.     $cart -> add(new Product("Котлеты",180,20));
  45.     $cart -> add(new Product("Рис",55,30));
  46.     $cart -> add(new Product("Гречка",48,20));
  47.     $cart -> show();
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement