/
3_chapter.php
170 lines (169 loc) · 4.56 KB
/
3_chapter.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
// class ShopProduct {
// public $numPages;
// public $playLength;
// public $title;
// public $producerMainName;
// public $producerFirstName;
// public $price;
// public $type;
// function __construct( $title, $firstName,
// $mainName, $price,
// $numPages=0, $playLength=0, $type) {
// $this->title = $title;
// $this->producerFirstName = $firstName;
// $this->producerMainName = $mainName;
// $this->price = $price;
// $this->numPages = $numPages;
// $this->playLength = $playLength;
// $this->type = $type;
// }
// function getNumberOfPages() {
// return $this->numPages;
// }
// function getPlayLength() {
// return $this->playLength;
// }
// function getProducer() {
// return "{$this->producerFirstName}".
// " {$this->producerMainName}";
// }
// function getSummaryLine() {
// $base = "{$this->title} ( {$this->producerMainName}, ";
// $base .= "{$this->producerFirstName} )";
// if ( $this->type == 'book' ) {
// $base .= ": page count - {$this->numPages}";
// } else if ( $this->type == 'cd' ) {
// $base .= ": playing time - {$this->playLength}";
// }
// echo $base;
// return $base;
// }
// }
// $firstCD = new ShopProduct("Hit-90", "Viktor", "Sydorenko", "10.54", "", "34:32", "cd");
// $firstCD->getSummaryLine();
//=============================
// class CdProduct {
// public $playLength;
// public $title;
// public $producerMainName;
// public $producerFirstName;
// public $price;
// function __construct( $title, $firstName,
// $mainName, $price,
// $playLength ) {
// $this->title = $title;
// $this->producerFirstName = $firstName;
// $this->producerMainName = $mainName;
// $this->price = $price;
// $this->playLength = $playLength;
// }
// function getPlayLength() {
// return $this->playLength;
// }
// function getSummaryLine() {
// $base = "{$this->title} ( {$this->producerMainName}, ";
// $base .= "{$this->producerFirstName} )";
// $base .= ": playing time - {$this->playLength}";
// return $base;
// }
// function getProducer() {
// return "{$this->producerFirstName}".
// " {$this->producerMainName}";
// }
// }
// class BookProduct {
// public $numPages;
// public $title;
// public $producerMainName;
// public $producerFirstName;
// public $price;
// function __construct( $title, $firstName,
// $mainName, $price,
// $numPages ) {
// $this->title = $title;
// $this->producerFirstName = $firstName;
// $this->producerMainName = $mainName;
// $this->price = $price;
// $this->numPages = $numPages;
// }
// function getNumberOfPages() {
// return $this->numPages;
// }
// function getSummaryLine() {
// $base = "{$this->title} ( {$this->producerMainName}, ";
// $base .= "{$this->producerFirstName} )";
// $base .= ": page count - {$this->numPages}";
// return $base;
// }
// function getProducer() {
// return "{$this->producerFirstName}".
// " {$this->producerMainName}";
// }
// }
//========================================
class ShopProduct {
public $title;
public $producerMainName;
public $producerFirstName;
public $price;
function __construct( $title, $firstName,
$mainName, $price ) {
$this->title = $title;
$this->producerFirstName = $firstName;
$this->producerMainName = $mainName;
$this->price = $price;
}
function getProducer() {
return "{$this->producerFirstName}".
" {$this->producerMainName}";
}
function getSummaryLine() {
$base = "{$this->title} ( {$this->producerMainName}, ";
$base .= "{$this->producerFirstName}, ";
$base .= "{$this->price} )";
return $base;
}
}
class CdProduct extends ShopProduct {
public $playLength;
function __construct( $title, $firstName,
$mainName, $price, $playLength ) {
parent::__construct( $title, $firstName,
$mainName, $price );
$this->playLength = $playLength;
}
function getPlayLength() {
return $this->playLength;
}
function getSummaryLine() {
$base = parent::getSummaryLine();
$base .= ": playing time - {$this->playLength}";
echo $base;
return $base;
}
}
class BookProduct extends ShopProduct {
public $numPages;
function __construct( $title, $firstName,
$mainName, $price, $numPages ) {
parent::__construct( $title, $firstName,
$mainName, $price );
$this->numPages = $numPages;
}
function getNumberOfPages() {
return $this->numPages;
}
function getSummaryLine() {
$base = parent::getSummaryLine();
$base .= ": page count - $this->numPages";
echo $base . "<br>";
return $base;
}
}
$book = new BookProduct("Master and Margaruta", "Mihail", "Bulgakov",
"45$", "456");
$shakira = new CdProduct("My Mister", "NoName", "Shakira",
"25$", "56:01");
$book->getSummaryLine();
$shakira->getSummaryLine();