大家好,我正在尝试在用户申请 overdraw 时收取 50 的 overdraw 费用。我的代码如下:
public void Withdraw(double amount){
int Charge = 50; //overdraft charge
if (balance - amount < 0) {
if ((balance -Charge)- amount <= -300) { //If withdraw + overdraft charge goes over -300 then overdraft limit has been exceeded
System.out.println("You have exceeded your Overdraft Limit, you will now be returned back to the menus");
} else { //if not exceeding bank balance
balance -= amount ; //subtract amount from balance
System.out.println("/");
}
}
}
它目前所做的只是在申请 overdraw 时显示负数,而不减去 overdraw 费用,如何才能使用户在申请 overdraw 时额外收取 50 美元?
最佳答案
您需要将代码修改为如下所示
} else { //if not exceeding bank balance
balance -= (amount + Charge) ; //subtract amount and charge from balance
System.out.println("You have withdrawen £" + amount);
System.err.println("You now have a balance of £" + balance);
System.out.println("/");
}
关于java - 如何申请 overdraw 费用来平衡java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36237599/