Java 如何设定透支限额

Java 如何设定透支限额,java,Java,我想做的是设置一个透支限额,即-150。如果用户的余额为-150,则用户不能再提取任何款项。我的代码如下: 提取方法 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("Insuffic

我想做的是设置一个透支限额,即-150。如果用户的余额为-150,则用户不能再提取任何款项。我的代码如下:

提取方法

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; 
        }
    }
}

}
公共作废取款(双倍金额){
如果(金额+5>余额){//如果金额和交易费大于余额,则申请透支
System.out.println(“资金不足”);
System.out.println(“您想申请一份草稿吗?”);
System.out.println(“1:是”);
System.out.println(“2:否,将我返回菜单”);
Choice=Option.nextLine();
if(选择相等信号情况(“1”)){
如果((余额=余额-金额+5)问题就出在这里:

if ((balance = balance - amount + 5) <= -150) {
注意更明确的计算(
if(balance-amount-5

if ((balance = balance - amount + 5) <= -150) {

请注意更明确的计算(
if(balance-amount-5
if((balance=balance-amount+5)
if((balance=balance-amount+5)除了上述所有答案之外,我将添加以下内容:

如果我有1$并且透支50$,那么我的账户可以在

1$-55$=-54$

但在这种情况下,这是不可能的

if (amount + FEES > balance) { // If amount and transaction fee is greater than balance then apply for overdraft
System.out.println("Insufficent funds");

除上述所有答案外,我将补充以下内容:

如果我有1$并且透支50$,那么我的账户可以在

1$-55$=-54$

但在这种情况下,这是不可能的

if (amount + FEES > balance) { // If amount and transaction fee is greater than balance then apply for overdraft
System.out.println("Insufficent funds");

堆栈溢出标记将变量解释为类,因为您使用大写字母编写它们。啊。堆栈溢出标记将变量解释为类,因为您使用大写字母编写它们。啊。