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

标签 java

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

相关文章:

java - 使用 ZK hibernate

java - 关于Java for-each附加变量声明

java - 解析多级括号之间的字符串到节点

java - 预期在 onBindViewHolder 上找到数组类型?

java - 在 write.xlsx 中使用 xlsx 包时出错

java - 需要有关我的 Selenium 框架模型的反馈

java - 如何将此 try-finally 更改为 try-with-resources?

java - 如何找到最大数组值的索引?

java.lang.ArrayIndexOutOfBoundsException : 21 >= 21

java - Weblogic 没有他们的 IDE?