teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

RecordManager.javaの修正

2020/08/30 01:38

投稿

icecleam
icecleam

スコア46

title CHANGED
File without changes
body CHANGED
@@ -14,8 +14,6 @@
14
14
  }
15
15
  ```
16
16
 
17
-
18
-
19
17
  add.jsp
20
18
  ```ここに言語を入力
21
19
  <%@ page session="false" language="java"
@@ -306,16 +304,20 @@
306
304
  list.add(new Item("A00301", "蛍光ペン6色セット", 420, 0, 0));
307
305
  list.add(new Item("A00401", "シャープペンシル", 100, 0, 0));
308
306
  list.add(new Item("A00501", "鉛筆H(1ダース)", 400, 0, 0));
309
- list.add(new Item("B00101", "無線綴ノートA4", 100, 0, 0));
307
+
310
- list.add(new Item("B00201", "リングノートA4", 120, 0, 0));
311
- list.add(new Item("B00301", "領収書", 350, 0, 0));
312
- list.add(new Item("C00101", "はさみ(青)", 128, 0, 0));
313
- list.add(new Item("C00201", "ステープラー", 338, 0, 0));
314
- list.add(new Item("C00301", "2穴パンチ", 128, 0, 0));
315
- list.add(new Item("C00401", "ゼムクリップ", 98, 0, 0));
316
- list.add(new Item("C00501", "消しゴム", 58, 0, 0));
317
308
  }
318
309
 
310
+ /**
311
+ * 更新した商品データ
312
+ * 確認ボタンを押すとlistに書き込む。
313
+ */
314
+ private static Item newItem;
315
+
316
+ /**
317
+ * 引数で指定された商品名に一致する商品データを返却
318
+ * @param name 検索キーとなる商品名
319
+ * @return 検索結果の商品データ
320
+ */
319
321
  public static Item findItem(String goodsName) {
320
322
  int index = list.indexOf(new Item("", goodsName, 0,0,0));
321
323
  return list.get(index);
@@ -345,11 +347,8 @@
345
347
  allList.add(item);
346
348
  }
347
349
 
348
- /**
349
- * リストに商品情報を 1 件削除する
350
- */
351
350
  public static void removeToAllList(Item newItem) {
352
- Item item = new Item(newItem.getId(), newItem.getName(), newItem.getPrice(),newItem.getQuantity(),newItem.getSubtotal());
351
+ Item item = new Item(newItem.getId(), newItem.getName(), newItem.getPrice(),newItem.getQuantity(),newItem.getSubtotal());
353
352
  allList.remove(item);
354
353
  }
355
354
 
@@ -368,14 +367,36 @@
368
367
  newItem = ni;
369
368
  }
370
369
 
370
+ public static Item getNewItem() {
371
+ return newItem;
372
+ }
373
+ public static String[] makeNameList() {
374
+ String[] nameList = new String[list.size()];
375
+ for (int i = 0; i < list.size(); i++) {
376
+ nameList[i] = (list.get(i)).getName();
377
+ }
378
+ return nameList;
379
+ }
380
+
381
+ public static Item selectItem(String name) {
382
+
383
+ for(Item item:list) {
384
+ if (item.getName().equals(name)) {
385
+ return item;
386
+ }
387
+ }
388
+ return null;
389
+ }
390
+
371
391
  public static int calTotal(int subtotal) {
372
392
  int total = 0;
373
393
  for(Item item:list) {
374
394
  total += item.getSubtotal();
375
395
  }
376
396
  return total;
377
- //return 0;
378
397
  }
398
+ }
399
+
379
400
  ```
380
401
 
381
402
  Item.java

2

誤字の修正、内容の修正

2020/08/30 01:38

投稿

icecleam
icecleam

スコア46

title CHANGED
File without changes
body CHANGED
@@ -12,12 +12,12 @@
12
12
  return total;
13
13
  //return 0;
14
14
  }
15
+ ```
15
16
 
16
17
 
17
18
 
18
-
19
19
  add.jsp
20
- ```jsp
20
+ ```ここに言語を入力
21
21
  <%@ page session="false" language="java"
22
22
  contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
23
23
  <%@ page import="java.time.LocalDate"%>
@@ -75,8 +75,11 @@
75
75
  </form:form>
76
76
  </body>
77
77
  </html>
78
+
78
79
  ```
79
80
 
81
+
82
+
80
83
  SalesSystemController.java
81
84
  ```java
82
85
  package jp.practice.sales;
@@ -108,13 +111,20 @@
108
111
  Item newItem = RecordManager.getNewItem();
109
112
  int sb = newItem.getPrice() * newItem.getQuantity();
110
113
  newItem.setSubtotal(sb);
111
- RecordManager.addToAllList(newItem);
114
+ RecordManager.addToAllList(newItem);
112
- RecordManager.calTotal(newItem.getSubtotal());
115
+ model.addAttribute("total", RecordManager.calTotal(sb));
113
- model.addAttribute("nameList", RecordManager.makeNameList());
116
+ model.addAttribute("nameList", RecordManager.makeNameList());
114
- model.addAttribute("allList", RecordManager.getallList());
117
+ model.addAttribute("allList", RecordManager.getallList());
115
- return "add";
116
- }
117
118
 
119
+ if (1 <= form.getQuantity() && form.getQuantity() <= 100) {
120
+ model.addAttribute("message2", ADDMSG);
121
+ return "add";
122
+ } else {
123
+ model.addAttribute("message", ERRMSG);
124
+ return "add";
125
+ }
126
+ }
127
+
118
128
  /**
119
129
  * 確認画面で登録を押した時に呼ばれる。データを登録して初期画面表示へ遷移する。
120
130
  * @param form フォームオブジェクト

1

calTotalメソッドの修正

2020/08/29 19:09

投稿

icecleam
icecleam

スコア46

title CHANGED
File without changes
body CHANGED
@@ -8,11 +8,10 @@
8
8
  int total = 0;
9
9
  for(Item item:list) {
10
10
  total += item.getSubtotal();
11
- return total;
12
11
  }
13
- return 0;
12
+ return total;
13
+ //return 0;
14
14
  }
15
- ```
16
15
 
17
16
 
18
17
 
@@ -363,9 +362,9 @@
363
362
  int total = 0;
364
363
  for(Item item:list) {
365
364
  total += item.getSubtotal();
366
- return total;
367
365
  }
368
- return 0;
366
+ return total;
367
+ //return 0;
369
368
  }
370
369
  ```
371
370