Commit 7bbae22b by Patryk Czarnik

"extract interface" - Ctrl+Alt+Shift+T : ogólny skrót do refactor this

parent 3efee6ce
package kalkulatory;
public class KalkulatorWielometodowy {
public interface KalkulatorWielometodowy {
int add(int x, int y);
public int add(int x, int y) {
return x + y;
}
int sub(int x, int y);
public int sub(int x, int y) {
return x - y;
}
int mul(int x, int y);
public int mul(int x, int y) {
return x * y;
}
public int div(int x, int y) {
return x / y;
}
int div(int x, int y);
}
package kalkulatory;
public class KalkulatorWielometodowyImpl implements KalkulatorWielometodowy {
@Override
public int add(int x, int y) {
return x + y;
}
@Override
public int sub(int x, int y) {
return x - y;
}
@Override
public int mul(int x, int y) {
return x * y;
}
@Override
public int div(int x, int y) {
return x / y;
}
}
......@@ -3,9 +3,14 @@ package kalkulatory;
import java.util.Scanner;
public class ProgramWielometodowy {
static void sprawdz(KalkulatorWielometodowy k) {
int wynik = k.add(2, 3);
System.out.println(wynik);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
KalkulatorWielometodowy k = new KalkulatorWielometodowy();
KalkulatorWielometodowy k = new KalkulatorWielometodowyImpl();
while(true) {
System.out.println("Podaj działanie jako + 2 3 lub Q, aby zakończyć");
String operacja = sc.next();
......@@ -23,6 +28,7 @@ public class ProgramWielometodowy {
};
System.out.printf("%d %s %d = %d\n", liczba1, operacja, liczba2, wynik);
}
sprawdz(k);
System.out.println("nara");
}
}
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