Commit 70f8d290 by Patryk Czarnik

LogikaKalkulatora static

parent 1c41c41a
......@@ -18,16 +18,12 @@ public class KalkulatorController {
@PostMapping
public String kalkulatorPost(Long liczba1, Long liczba2, String operacja, Model model) {
if(liczba1 != null && liczba2 != null && operacja != null) {
Long wynik = switch(operacja) {
case "+" -> liczba1 + liczba2;
case "-" -> liczba1 - liczba2;
case "*" -> liczba1 * liczba2;
case "/" -> liczba1 / liczba2;
default -> 0L;
};
Long wynik = LogikaKalkulatora.oblicz(liczba1, liczba2, operacja);
model.addAttribute("wynik", wynik);
}
return "kalkulator.html";
}
}
package com.example.demo;
public class LogikaKalkulatora {
public static long oblicz(long liczba1, long liczba2, String operacja) {
return switch(operacja) {
case "+" -> liczba1 + liczba2;
case "-" -> liczba1 - liczba2;
case "*" -> liczba1 * liczba2;
case "/" -> liczba1 / liczba2;
default -> 0L;
};
}
}
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