Commit 79e29206 by Patryk Czarnik

Konto - wersja z bool

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