回答編集履歴
2
修正
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
|
5
|
+
追記
|
6
6
|
|
7
7
|
```php
|
8
8
|
|
1
修正
test
CHANGED
@@ -1 +1,51 @@
|
|
1
|
-
newのときに第2引数にt/f送るだけでは
|
1
|
+
newのときに第2引数にt/f送るだけでは
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
```php
|
8
|
+
|
9
|
+
<?php
|
10
|
+
|
11
|
+
class Item {
|
12
|
+
|
13
|
+
private $taxRate = 0.08;
|
14
|
+
|
15
|
+
//public $price; //コメントアウトはずす
|
16
|
+
|
17
|
+
//public $included = false;//コメントアウトはずす
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
public function __construct ( int $price, $included = false ) {
|
22
|
+
|
23
|
+
$this->price = $price;
|
24
|
+
|
25
|
+
$this->included = $included;
|
26
|
+
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
public function tax():int {
|
32
|
+
|
33
|
+
if ( $included ) { // true = 内税 $this->included に変更
|
34
|
+
|
35
|
+
return $this->price * $this->taxRate;
|
36
|
+
|
37
|
+
} else { // false = 外税
|
38
|
+
|
39
|
+
return $this->price + ( $this->price * $this->taxRate );
|
40
|
+
|
41
|
+
}
|
42
|
+
|
43
|
+
}
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
```
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
[PHPマニュアル](https://www.php.net/manual/ja/language.oop5.properties.php)も参考にしてください。
|