1 以下のような簡易電卓のWebアプリケーションを①~⑧を埋めることで完成させなさい。

簡易電卓 入力画面
2つの数値、数値1、2を入れて四則演算子を選択し、「submit」ボタンを押すと、

簡易電卓 結果表示画面
「〇〇算の結果:△」と計算結果が表示される。
割る数に0が入力された場合は「0での割り算はできません」と表示する。
ヒント:アドレスバーの最後がどうなっているかよく観察すること。
<ソースコード①>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
<html> <head> <title>calculator</title> <meta charset="UTF-8"> </head> <body> <form action="Caluculator.jsp" method="①"> <label for= "num1"><b>数値1</b></label> <input type= "text" name = "n1"><br><br> <label for = "num2"><b>数値2</b></label> <input type= "text" name = "n2"><br><br> <input type = "radio" name = "ope" value = "Add">+ <input type = "radio" name = "ope" value = "Sub">-<br> <input type = "radio" name = "ope" value = "mul">* <input type = "radio" name = "ope" value = "div">/<br><br> <input type="submit" value="submit"> </form> </body> </html> |
<ソースコード②>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Caluculator</title> </head> <body> <% double num1 = Double.parseDouble(request.getParameter("②")); double num2 = Double.parseDouble(request.getParameter("③")); String operation = request.getParameter("④"); if (operation.equals("⑤")) { double add = num1 + num2; out.println("足し算の結果: " + add); } else if (operation.equals("⑥")) { double sub = num1 - num2; out.println("引き算の結果: " + sub); } else if (operation.equals("⑦")) { double mul = num1 * num2; out.println("掛け算の結果: " + mul); } else if (operation.equals("⑧")) { if (num2 == 0) { out.println("0での割り算はできません"); } else { double div = num1 / num2; out.println("割り算の結果: " + div); } } %> </body> </html> |
2 上記簡易電卓を下記のスケルトンから書き起こしなさい。
1 2 3 4 5 6 7 8 9 |
<html> <head> <title>calculator</title> <meta charset="UTF-8"> </head> <body> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 |
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Caluculator</title> </head> <body> <% %> </body> </html> |
3.オリジナル問題作成
将来の後輩のために良い問題が出来たら教えてください。