Commit 39a77ced by Patryk Czarnik

kalkulator - select/option

parent 3fa7f49a
......@@ -30,9 +30,15 @@ public class Kalkulator extends HttpServlet {
out.append("""
<form>
Podaj pierwszą liczbę: <input type='text' name='liczba1'><br>
Podaj drugą liczbę: <input type='text' name='liczba2'><br>
Podaj znak działania: <input type='text' name='operacja'><br>
Podaj pierwszą liczbę: <input type='number' name='liczba1'><br>
Podaj drugą liczbę: <input type='number' name='liczba2'><br>
Podaj znak działania:
<select name='operacja'>
<option value='+'>+</option>
<option value='-'>+</option>
<option value='*'>×</option>
<option value='/'>÷</option>
</select><br>
<button>Oblicz</button>
</form>
""");
......@@ -41,6 +47,7 @@ public class Kalkulator extends HttpServlet {
String liczba1 = request.getParameter("liczba1");
String liczba2 = request.getParameter("liczba2");
if(operacja != null && liczba1 != null && liczba2 != null) {
try {
long x = Long.parseLong(liczba1);
long y = Long.parseLong(liczba2);
long wynik = switch(operacja) {
......@@ -52,6 +59,9 @@ public class Kalkulator extends HttpServlet {
default -> 0;
};
out.append("<div>Wynik: " + wynik + "</div>");
} catch (Exception e) {
out.append("<div>Błąd: " + e + "</div>");
}
}
out.append("""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment