gpt4 book ai didi

java - 如何申请 overdraw 费用来平衡java

转载 作者:行者123 更新时间:2023-11-30 07:30:20 25 4
gpt4 key购买 nike

大家好,我正在尝试在用户申请 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com