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