質問編集履歴
4
誤植
test
CHANGED
File without changes
|
test
CHANGED
@@ -567,11 +567,3 @@
|
|
567
567
|
</html>
|
568
568
|
|
569
569
|
```
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
12/21 現在
|
574
|
-
|
575
|
-
ビルドし直したところエラーが変化しました。
|
576
|
-
|
577
|
-
![イメージ説明](38acecea15583f5331a8e8098c261cb4.png)
|
3
エラーコード画像の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -567,3 +567,11 @@
|
|
567
567
|
</html>
|
568
568
|
|
569
569
|
```
|
570
|
+
|
571
|
+
|
572
|
+
|
573
|
+
12/21 現在
|
574
|
+
|
575
|
+
ビルドし直したところエラーが変化しました。
|
576
|
+
|
577
|
+
![イメージ説明](38acecea15583f5331a8e8098c261cb4.png)
|
2
htmlのソースコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -509,3 +509,61 @@
|
|
509
509
|
|
510
510
|
|
511
511
|
```
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
```html
|
516
|
+
|
517
|
+
<!DOCTYPE html>
|
518
|
+
|
519
|
+
<html>
|
520
|
+
|
521
|
+
<head>
|
522
|
+
|
523
|
+
<meta charset="UTF-8">
|
524
|
+
|
525
|
+
<title>口座操作画面</title>
|
526
|
+
|
527
|
+
</head>
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
<body>
|
532
|
+
|
533
|
+
<center>
|
534
|
+
|
535
|
+
<div id="top-main">
|
536
|
+
|
537
|
+
<h1>いらっしゃいませ</h1>
|
538
|
+
|
539
|
+
<h2>操作をお選び下さい</h2>
|
540
|
+
|
541
|
+
</div>
|
542
|
+
|
543
|
+
<!-- 選択 -->
|
544
|
+
|
545
|
+
<nav class="menu">
|
546
|
+
|
547
|
+
<ul>
|
548
|
+
|
549
|
+
<li class="menu_item"><a href="open">口座開設</a></li>
|
550
|
+
|
551
|
+
<li class="menu_item"><a href="close">口座解約</a></li>
|
552
|
+
|
553
|
+
<li class="menu_item"><a href="deposit">お預入れ</a></li>
|
554
|
+
|
555
|
+
<li class="menu_item"><a href="withdraw">お引出し</a></li>
|
556
|
+
|
557
|
+
<li class="menu_item"><a href="balance">残高照会</a></li>
|
558
|
+
|
559
|
+
</ul>
|
560
|
+
|
561
|
+
</nav>
|
562
|
+
|
563
|
+
</center>
|
564
|
+
|
565
|
+
</body>
|
566
|
+
|
567
|
+
</html>
|
568
|
+
|
569
|
+
```
|
1
今回使用しているソースコードを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -9,3 +9,503 @@
|
|
9
9
|
|
10
10
|
|
11
11
|
コードなどが必要でしたら、ご指摘下さい。
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
```java
|
16
|
+
|
17
|
+
public class Account{
|
18
|
+
|
19
|
+
private String name; //口座名
|
20
|
+
|
21
|
+
private int balance; //口座の残高
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
public Account(String myName){ //口座名
|
26
|
+
|
27
|
+
name = myName;
|
28
|
+
|
29
|
+
balance = 0;
|
30
|
+
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
public int deposit(int amount){ //預金額
|
36
|
+
|
37
|
+
if(amount <= 0)
|
38
|
+
|
39
|
+
return -3;
|
40
|
+
|
41
|
+
else
|
42
|
+
|
43
|
+
balance += amount;
|
44
|
+
|
45
|
+
return 0;
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
public int withdraw(int amount){ //出金額
|
52
|
+
|
53
|
+
if(amount <= 0)
|
54
|
+
|
55
|
+
return -3;
|
56
|
+
|
57
|
+
else if(amount > balance)
|
58
|
+
|
59
|
+
return -1;
|
60
|
+
|
61
|
+
else
|
62
|
+
|
63
|
+
balance -= amount;
|
64
|
+
|
65
|
+
return 0;
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
public int showBalance(){ //残高照会
|
72
|
+
|
73
|
+
return balance;
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
```java
|
84
|
+
|
85
|
+
import java.io.IOException;
|
86
|
+
|
87
|
+
import java.io.PrintWriter;
|
88
|
+
|
89
|
+
import javax.servlet.ServletException;
|
90
|
+
|
91
|
+
import javax.servlet.http.HttpServlet;
|
92
|
+
|
93
|
+
import javax.servlet.http.HttpServletRequest;
|
94
|
+
|
95
|
+
import javax.servlet.http.HttpServletResponse;
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
public class BankServlet extends HttpServlet {
|
100
|
+
|
101
|
+
private ExtendedBank bank; /* 口座の管理をするオブジェクト */
|
102
|
+
|
103
|
+
public BankServlet() { /* bankを初期化する */
|
104
|
+
|
105
|
+
bank = new ExtendedBank();
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
112
|
+
|
113
|
+
throws IOException, ServletException {
|
114
|
+
|
115
|
+
String b_name = request.getParameter("name");
|
116
|
+
|
117
|
+
int result = bank.open(b_name);
|
118
|
+
|
119
|
+
response.setContentType("text/html; charset=UTF-8");
|
120
|
+
|
121
|
+
PrintWriter pw = response.getWriter();
|
122
|
+
|
123
|
+
/* 口座開設処理 */
|
124
|
+
|
125
|
+
if(result == 0) { /* 口座開設成功のHTML生成*/
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
pw.println(
|
130
|
+
|
131
|
+
"<!DOCTYPE html>"
|
132
|
+
|
133
|
+
+"<html>"
|
134
|
+
|
135
|
+
+"<head>"
|
136
|
+
|
137
|
+
+"<meta charset=\"UTF-8\">"
|
138
|
+
|
139
|
+
+"</head>"
|
140
|
+
|
141
|
+
+"<body>"
|
142
|
+
|
143
|
+
+"<div class=\"main\">"
|
144
|
+
|
145
|
+
+"<h1>口座開設成功</h1>"
|
146
|
+
|
147
|
+
+"<h2>+ b_name +様の口座を開設致しました!</h2>"
|
148
|
+
|
149
|
+
+"</div>"
|
150
|
+
|
151
|
+
+"<a class=\"success\" href=\"index.html\">メインメニューに戻る</a>"
|
152
|
+
|
153
|
+
+"</body>"
|
154
|
+
|
155
|
+
+"</html>");
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
} else { /*口座開設失敗のHTML生成 */
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
pw.println(
|
164
|
+
|
165
|
+
"<!DOCTYPE html>"
|
166
|
+
|
167
|
+
+"<html>"
|
168
|
+
|
169
|
+
+"<head>"
|
170
|
+
|
171
|
+
+"<meta charset=\"UTF-8\">"
|
172
|
+
|
173
|
+
+"</head>"
|
174
|
+
|
175
|
+
+"<body>"
|
176
|
+
|
177
|
+
+"<div class=\"main\">"
|
178
|
+
|
179
|
+
+"<h1>口座開設失敗</h1>"
|
180
|
+
|
181
|
+
+"<h2>+ b_name +様の口座は既に存在しております。</h2>"
|
182
|
+
|
183
|
+
+"</div>"
|
184
|
+
|
185
|
+
+"<a class=\"success\" href=\"index.html\">メインメニューに戻る</a>"
|
186
|
+
|
187
|
+
+"</body>"
|
188
|
+
|
189
|
+
+"</html>");
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
```
|
198
|
+
|
199
|
+
```java
|
200
|
+
|
201
|
+
import java.util.Hashtable;
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
public class ExtendedBank{
|
206
|
+
|
207
|
+
private Hashtable<String,Account>customer; // 口座リスト
|
208
|
+
|
209
|
+
private int balance; // 残高格納用
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
public ExtendedBank(){ // 口座リスト初期化
|
214
|
+
|
215
|
+
customer = new Hashtable<String,Account>();
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
public int open(String name){ // 口座開設
|
222
|
+
|
223
|
+
Account myaccount = customer.get(name);
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
if(customer.get(name) != null) return -7;
|
228
|
+
|
229
|
+
else{
|
230
|
+
|
231
|
+
customer.put(name,new Account(name));
|
232
|
+
|
233
|
+
return 0;
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
public int close(String name){ // 口座解約
|
242
|
+
|
243
|
+
Account myaccount = customer.get(name);
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
if(customer.get(name) != null){
|
248
|
+
|
249
|
+
if(myaccount.showBalance() == 0){
|
250
|
+
|
251
|
+
customer.remove(name);
|
252
|
+
|
253
|
+
return 0;
|
254
|
+
|
255
|
+
}else return -1;
|
256
|
+
|
257
|
+
}else return -7;
|
258
|
+
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
public int withdraw(String name,int amount){ // 引き出し
|
266
|
+
|
267
|
+
Account myaccount = customer.get(name);
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
if(customer.get(name) != null){
|
272
|
+
|
273
|
+
if(amount <= 0)
|
274
|
+
|
275
|
+
return -3;
|
276
|
+
|
277
|
+
else if(amount > balance)
|
278
|
+
|
279
|
+
return -1;
|
280
|
+
|
281
|
+
else{
|
282
|
+
|
283
|
+
balance -= amount;
|
284
|
+
|
285
|
+
return 0;
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
}else return -7;
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
public int deposit(String name,int amount){ // 預金
|
298
|
+
|
299
|
+
Account myaccount = customer.get(name);
|
300
|
+
|
301
|
+
if(customer.get(name) == null)
|
302
|
+
|
303
|
+
return -7;
|
304
|
+
|
305
|
+
else if(amount <= 0)
|
306
|
+
|
307
|
+
return -3;
|
308
|
+
|
309
|
+
else{
|
310
|
+
|
311
|
+
balance += amount;
|
312
|
+
|
313
|
+
return 0;
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
public int showBalance(String name){ // 残高照会
|
324
|
+
|
325
|
+
Account myaccount = customer.get(name);
|
326
|
+
|
327
|
+
if(customer.get(name) != null) return myaccount.showBalance();
|
328
|
+
|
329
|
+
else return -7;
|
330
|
+
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
// ExtendedBank要素
|
336
|
+
|
337
|
+
// 預金
|
338
|
+
|
339
|
+
public int deposit(String name,String amount){ // name:口座名 d_amount:預金額
|
340
|
+
|
341
|
+
int result;
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
try{
|
346
|
+
|
347
|
+
result = Integer.parseInt(amount);
|
348
|
+
|
349
|
+
}catch(NumberFormatException e){
|
350
|
+
|
351
|
+
if(this.showBalance(name) == -7)
|
352
|
+
|
353
|
+
return -7;
|
354
|
+
|
355
|
+
else
|
356
|
+
|
357
|
+
return -4;
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
|
362
|
+
|
363
|
+
result = Integer.parseInt(amount);
|
364
|
+
|
365
|
+
if(result <= 0)
|
366
|
+
|
367
|
+
return -3;
|
368
|
+
|
369
|
+
else{
|
370
|
+
|
371
|
+
balance += result;
|
372
|
+
|
373
|
+
return 0;
|
374
|
+
|
375
|
+
}
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
// 引き出し
|
382
|
+
|
383
|
+
public int withdraw(String name,String amount){ // name:口座名 w_amount:引出額
|
384
|
+
|
385
|
+
int result;
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
try{
|
390
|
+
|
391
|
+
result = Integer.parseInt(amount);
|
392
|
+
|
393
|
+
}catch(NumberFormatException e){
|
394
|
+
|
395
|
+
if(this.showBalance(name) == -7)
|
396
|
+
|
397
|
+
return -7;
|
398
|
+
|
399
|
+
else
|
400
|
+
|
401
|
+
return -4;
|
402
|
+
|
403
|
+
}
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
result = Integer.parseInt(amount);
|
408
|
+
|
409
|
+
if(result <= 0)
|
410
|
+
|
411
|
+
return -3;
|
412
|
+
|
413
|
+
else if(result > balance)
|
414
|
+
|
415
|
+
return -1;
|
416
|
+
|
417
|
+
else{
|
418
|
+
|
419
|
+
balance -= result;
|
420
|
+
|
421
|
+
return 0;
|
422
|
+
|
423
|
+
}
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
}
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
```
|
432
|
+
|
433
|
+
```java
|
434
|
+
|
435
|
+
import java.io.IOException;
|
436
|
+
|
437
|
+
import java.io.PrintWriter;
|
438
|
+
|
439
|
+
import javax.servlet.ServletException;
|
440
|
+
|
441
|
+
import javax.servlet.http.HttpServlet;
|
442
|
+
|
443
|
+
import javax.servlet.http.HttpServletRequest;
|
444
|
+
|
445
|
+
import javax.servlet.http.HttpServletResponse;
|
446
|
+
|
447
|
+
|
448
|
+
|
449
|
+
public class OpenServlet extends HttpServlet{
|
450
|
+
|
451
|
+
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
452
|
+
|
453
|
+
throws IOException, ServletException {
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
response.setContentType("text/html; charset=UTF-8");
|
458
|
+
|
459
|
+
PrintWriter pw = response.getWriter();
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
pw.println(
|
464
|
+
|
465
|
+
"<!DOCTYPE html>"
|
466
|
+
|
467
|
+
+"<html>"
|
468
|
+
|
469
|
+
+"<head>"
|
470
|
+
|
471
|
+
+"<meta charset=\"utf-8\">"
|
472
|
+
|
473
|
+
+"</head>"
|
474
|
+
|
475
|
+
+"<body>"
|
476
|
+
|
477
|
+
+"<div class=\"main\">"
|
478
|
+
|
479
|
+
+"<h1>口座開設</h1>"
|
480
|
+
|
481
|
+
+"<form action=\"bank\" method=\"GET\">"
|
482
|
+
|
483
|
+
+"<input type=\"hidden\" name=\"command\" value=\"open\">"
|
484
|
+
|
485
|
+
+"<div class=\"input\">"
|
486
|
+
|
487
|
+
+"<label for=\"account\">口座名</label>"
|
488
|
+
|
489
|
+
+"<input type=\"text\" name=\"name\" placeholder=\"入力された口座名\">"
|
490
|
+
|
491
|
+
+"<input type=\"submit\" value = \"確認\">"
|
492
|
+
|
493
|
+
+"</div>"
|
494
|
+
|
495
|
+
+"</form>"
|
496
|
+
|
497
|
+
+"<a class=\"cancel\" href=\"index.html\">キャンセル</a>"
|
498
|
+
|
499
|
+
+"</div>"
|
500
|
+
|
501
|
+
+"</body>"
|
502
|
+
|
503
|
+
+"</html>");
|
504
|
+
|
505
|
+
}
|
506
|
+
|
507
|
+
}
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
```
|