1.簡易電卓①
以下のような簡易電卓のWebアプリケーションを①~⑦を埋めることで完成させなさい。
簡易電卓 入力画面
2つの数値、数値1、2を入れて四則演算子を選択し、「submit」ボタンを押すと、
簡易電卓 結果表示画面
「〇〇算の結果:△」と計算結果が表示される。
割る数に0が入力された場合は「0での割り算はできません」と表示する。
ヒント:アドレスバーの最後がどうなっているかよく観察すること。
<ソースコード① ファイル名:Q01.jsp>
<html>
<head>
<title>calculator</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="Caluculator.jsp" method="①">
<label for= "n1"><b>数値1</b></label>
<input type= "text" name = "num1" id="n1"><br>
<label for = "n2"><b>数値2</b></label>
<input type= "text" name = "num2" id="n2"><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>
<input type="submit" value="submit">
</form>
</body>
</html>
<ソースコード② ファイル名:Caluculator.jsp>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Caluculator</title>
</head>
<body>
<%
double num1 = Double.parseDouble(②);
double num2 = Double.parseDouble(③);
String operation = request.getParameter("ope");
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.簡易電卓②
上記簡易電卓を下記のスケルトンから書き起こしなさい。
<html>
<head>
<title>calculator</title>
<meta charset="UTF-8">
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Caluculator</title>
</head>
<body>
<%
%>
</body>
</html>
3.オリジナル問題作成
将来の後輩のために良い問題が出来たら教えてください。