質問編集履歴

1

コードの修正

2022/08/06 07:34

投稿

pon.taro
pon.taro

スコア1

test CHANGED
File without changes
test CHANGED
@@ -25,11 +25,9 @@
25
25
  }
26
26
  }
27
27
 
28
- class Cart extends Items {
28
+ class Cart {
29
29
  private $Itemlist;
30
-
31
- public function getTotalPrice() {
32
- return $this->price * $item;
30
+ // 合計金額を出す処理をしたい
33
31
  }
34
32
  }
35
33
 
@@ -39,14 +37,17 @@
39
37
 
40
38
  $items = array($t_shirt, $cap, $socks);
41
39
 
40
+ $totalprice= 0;
42
41
  foreach ($items as $item) {
43
42
  print $item->getName();
44
43
  print $item->getPrice();
44
+ $totalprice += $item->getPrice();
45
45
  }
46
+ print $totalprice;
46
47
 
47
48
  ```
48
49
 
49
- ### 試したこと
50
+ ### 補足
50
- オブジェクト指向継承はなく集約を調べまたが、書き方がわらず困っています
51
+ CartラスでItemsクラスのリストの合計金額を出力することは不可能でしょうか。
51
52
 
52
53