Commit 7e0ab3b7 by Patryk Czarnik

Kalkulator - wiele działań

parent 6d75f364
...@@ -18,7 +18,7 @@ public class Kalkulator extends HttpServlet { ...@@ -18,7 +18,7 @@ public class Kalkulator extends HttpServlet {
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Rozmowa serlwetowa</title> <title>Kalulator serlwetowy</title>
</head> </head>
<body>"""; <body>""";
final String formularz = """ final String formularz = """
...@@ -45,15 +45,21 @@ public class Kalkulator extends HttpServlet { ...@@ -45,15 +45,21 @@ public class Kalkulator extends HttpServlet {
out.println(poczatek); out.println(poczatek);
out.println(formularz); out.println(formularz);
String parametr1 = request.getParameter("liczba1");
String parametr2 = request.getParameter("liczba2");
String operacja = request.getParameter("operacja");
if(parametr1 != null && !parametr1.isBlank()
&& parametr2 != null && !parametr1.isBlank()
&& operacja != null && !operacja.isBlank()) {
try { try {
long liczba1 = Long.parseLong(request.getParameter("liczba1")); long liczba1 = Long.parseLong(parametr1);
long liczba2 = Long.parseLong(request.getParameter("liczba2")); long liczba2 = Long.parseLong(parametr2);
String operacja = (request.getParameter("operacja"));
long wynik = oblicz(liczba1, liczba2, operacja); long wynik = oblicz(liczba1, liczba2, operacja);
out.println("<div>Wynik " + wynik + "</div>"); out.printf("<div>%d %s %d = <strong>%d</strong></div>", liczba1, operacja, liczba2, wynik);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
out.println("Niepoprawny format liczby"); out.println("Niepoprawny format liczby");
} }
}
out.println(koniec); out.println(koniec);
} }
......
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