回答編集履歴

2

修正

2019/04/09 01:52

投稿

m.ts10806
m.ts10806

スコア80859

test CHANGED
@@ -3,6 +3,8 @@
3
3
  お好きなのをどうぞ。
4
4
 
5
5
 
6
+
7
+ **※おそらく何かの問題集や課題のようなので自身が理解できるものから採用してください**
6
8
 
7
9
 
8
10
 

1

修正

2019/04/09 01:52

投稿

m.ts10806
m.ts10806

スコア80859

test CHANGED
@@ -70,6 +70,66 @@
70
70
 
71
71
  ```
72
72
 
73
+ ```php
74
+
75
+ //消費税決まってるので他にも価格がきたときのために関数化とか
76
+
77
+ function taxCalc(int $price = 0):int
78
+
79
+ {
80
+
81
+ $taxRate = 0.08;
82
+
83
+ return $price +($price * $taxRate);
84
+
85
+ }
86
+
87
+ $price = 1000;
88
+
89
+ echo "税込価格は".taxCalc($price)."円です";
90
+
91
+ ```
92
+
93
+ ```
94
+
95
+ //商品扱うという観点からクラスにするとか
96
+
97
+ class Item
98
+
99
+ {
100
+
101
+ private $taxRate = 0.08;
102
+
103
+ public $price = 0;
104
+
105
+ public $name = '';
106
+
107
+ function __construct(string $name='',int $price = 0)
108
+
109
+ {
110
+
111
+ $this->name = $name;
112
+
113
+ $this->price = $price;
114
+
115
+ }
116
+
117
+ function taxPrice():int
118
+
119
+ {
120
+
121
+ return $this->price +($this->price * $this->taxRate);
122
+
123
+ }
124
+
125
+ }
126
+
127
+ $item = new Item('りんご',1000);
128
+
129
+ echo "税込価格は".$item->taxPrice()."円です";
130
+
131
+ ```
132
+
73
133
 
74
134
 
75
135
  etc.