Commit 55f8d5c6 by Patryk Czarnik

Extract interface

parent 358fa3bf
package alx.kalkulator; package alx.kalkulator;
import org.springframework.stereotype.Component; public interface LogikaKalkulatora {
long oblicz(long liczba1, long liczba2, String operacja);
@Component
public class LogikaKalkulatora {
public long oblicz(long liczba1, long liczba2, String operacja) {
long wynik = switch (operacja) {
case "+" -> liczba1 + liczba2;
case "-" -> liczba1 - liczba2;
case "*" -> liczba1 * liczba2;
case "/" -> liczba1 / liczba2;
default -> 0L;
};
return wynik;
}
} }
package alx.kalkulator;
import org.springframework.stereotype.Component;
@Component
public class LogikaKalkulatoraImpl implements LogikaKalkulatora {
@Override
public long oblicz(long liczba1, long liczba2, String operacja) {
long wynik = switch (operacja) {
case "+" -> liczba1 + liczba2;
case "-" -> liczba1 - liczba2;
case "*" -> liczba1 * liczba2;
case "/" -> liczba1 / liczba2;
default -> 0L;
};
return wynik;
}
}
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