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,14 +45,20 @@ public class Kalkulator extends HttpServlet { ...@@ -45,14 +45,20 @@ public class Kalkulator extends HttpServlet {
out.println(poczatek); out.println(poczatek);
out.println(formularz); out.println(formularz);
try { String parametr1 = request.getParameter("liczba1");
long liczba1 = Long.parseLong(request.getParameter("liczba1")); String parametr2 = request.getParameter("liczba2");
long liczba2 = Long.parseLong(request.getParameter("liczba2")); String operacja = request.getParameter("operacja");
String operacja = (request.getParameter("operacja")); if(parametr1 != null && !parametr1.isBlank()
long wynik = oblicz(liczba1, liczba2, operacja); && parametr2 != null && !parametr1.isBlank()
out.println("<div>Wynik " + wynik + "</div>"); && operacja != null && !operacja.isBlank()) {
} catch (NumberFormatException e) { try {
out.println("Niepoprawny format liczby"); long liczba1 = Long.parseLong(parametr1);
long liczba2 = Long.parseLong(parametr2);
long wynik = oblicz(liczba1, liczba2, operacja);
out.printf("<div>%d %s %d = <strong>%d</strong></div>", liczba1, operacja, liczba2, wynik);
} catch (NumberFormatException e) {
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