Commit 79e29206 by Patryk Czarnik

Konto - wersja z bool

parent cd360f46
......@@ -35,8 +35,14 @@ public class Konto {
return saldo;
}
public void wplata(int kwota) {
saldo += kwota;
public boolean wplata(int kwota) {
if(kwota > 0) {
saldo += kwota;
return true;
} else {
System.err.println("Kwota wpłaty nie jest dodatnia");
return false;
}
}
public void wyplata(int kwota) {
......
......@@ -30,8 +30,11 @@ public class ProgramBankowy {
System.out.print("Podaj kwotę wpłaty: ");
kwota = sc.nextInt();
sc.nextLine();
konto.wplata(kwota);
System.out.println("Pieniądze zostały wpłacone");
if(konto.wplata(kwota)) {
System.out.println("Pieniądze zostały wpłacone");
} else {
System.out.println("nie ma wpłaty");
}
}
case "Y" -> {
System.out.print("Podaj kwotę wypłaty: ");
......
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