was ich versuche, ist ein Überziehungslimit festlegen, d. H. -150 der Benutzer kann nicht weiter abziehen, wenn ihr Kontostand -150 ist. Mein Code ist unten:So legen Sie ein Überziehungslimit fest
Methode zurückziehen
public void Withdraw(double amount){
if (amount + 5 > balance){ //If amount and transaction fee is greater than balance then apply for overdraft
System.out.println("Insufficent funds");
System.out.println("Would you like to apply for an ovedraft?");
System.out.println("1:Yes");
System.out.println("2:No, return me back to menus");
Choice = Option.nextLine();
if (Choice.equalsIgnoreCase("1")){
if((balance = balance - amount+5)<=-150){ //If balance is grater than 150 , apply for overdraft
System.out.println("You have exceeded your Overdraft Limit, you will now be returned back to the menus");
return;
}
else{ //if not exceeding bank balance
balance -= amount + 5;
System.out.println("You have withdrawen £" + amount);
System.err.println("You now have a balance of £" +balance);
return;
}
}
}
}
Sie sind alle in der gleichen Klasse, die „Konto“ ist, was jetzt passiert, ist, dass die Nachricht auftritt - ("Sie haben überschritten Ihre Überziehungs Limit, Sie werden jetzt zurück zu den Menüs ") und kehrt zurück zu den Menüs, aber wenn ich gehe, um das Guthaben zu überprüfen, wird das Geld noch abgezogen und zeigt ein Guthaben, das über -150 z. B. geht. -190 wie kann ich es machen, dass -150 die Grenze ist und nicht mehr abziehen. Hoffe, die Frage wurde verstanden.
Stack-Überlauf Abschlag interpretiert Ihre Variablen als Klassen führen, dass Sie sie mit einem Großbuchstaben schreiben. Pfui. – Gendarme