-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShopProduct.php
112 lines (97 loc) · 2.26 KB
/
ShopProduct.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Created by PhpStorm.
* User: dobrodeev
* Date: 01.08.2018
* Time: 20:15
*/
class ShopProduct
{
public $name;
public $lastname;
public $title;
protected $price;
public $discount;
/**
* ShopProduct constructor.
* @param $name
* @param $lastname
* @param $price
* @param $discount
*/
public function __construct($name, $lastname, $title, $price)
{
$this->name = $name;
$this->lastname = $lastname;
$this->title = $title;
$this->price = $price;
}
public function setDiscount($num)
{
$this->discount = $num;
}
public function getPrice()
{
return($this->price - $this->discount);
}
public function getName()
{
return "{$this->name}"."{$this->lastname}";
}
public function getLine()
{
$base = "$this->name"."$this->lastname"."$this->title";
return $base;
}
}
class CDproduct extends ShopProduct
{
public $play;
/**
* CDproduct constructor.
* @param $play
*/
public function __construct($title, $name, $lastname, $price, $play)
{
parent::__construct($title, $name, $lastname, $price);
$this->play = $play;
}
public function getPlay()
{
return $this->play;
}
public function getLine()
{
// return parent::getLine(); // TODO: Change the autogenerated stub
$base = parent::getLine()."$this->play";
return $base;
}
}
class BookProduct extends ShopProduct
{
public $page;
/**
* BookProduct constructor.
* @param $page
*/
public function __construct($title, $name, $lastname, $price, $page)
{
parent::__construct($title, $name, $lastname, $price);
$this->page = $page;
}
public function getPages()
{
return $this->page;
}
public function getLine()
{
// return parent::getLine(); // TODO: Change the autogenerated stub
$base = parent::getLine()."$this->page";
return $base;
}
}
$product1 = new BookProduct('Iron World', 'Man', 'Surname', 167, 87);
$product2 = new CDproduct('Iron World', 'Man', 'Surname', 329, 46);
$product1->setDiscount(0.5);
echo $product1->getPrice();
echo $product1->getLine();