gpt4 book ai didi

Java实现储蓄账户到支票账户银行转账的方法

转载 作者:行者123 更新时间:2023-12-01 23:23:47 25 4
gpt4 key购买 nike

我在帐户类中有以下方法

public void Transfer(int accountNo, double amount)
{
this.accountNo = accountNo;
double savingBal= this.getSavingBal();
if (this.savingBal > amount)
{this.savingBal=-amount;
this.checkingBal=+amount;
}
else
{
System.out.println("Insufficent fonds into savings account");
}

}

并将此代码放入主类中:

//

 Account b = new Account();

//

  System.out.println("Please mention the amout you whish to transfer and the account");
amount = s.nextDouble();
accountNo = s.nextInt();
b.Transfer(accountNo, amount);

但是打印到控制台的结果始终是:“资金不足”

请帮忙,

此致,

完整帐户类别

package atmsimulation;
import java.util.*;

public class Account {
private int accountNo;
private double checkingBal;
private double savingBal;

//Scanner sc = new Scanner(System.in);

Account ()
{
this.checkingBal=0;
this.savingBal=0;
this.accountNo=0;
}

public Account(int accountNo, double checkingBal, double savingBal) {
this.accountNo = accountNo;
this.checkingBal = checkingBal;
this.savingBal = savingBal;
}
//makes a @Payment
public void Payment(double amount)
{
this.checkingBal=-amount;
}
//makes a @Deposit
public void Deposit(double amount)
{
this.checkingBal=+amount;
}
//makeks a transfer from @savings into @checking account
public void Transfer(int accountNo, double amount)
{
this.accountNo = accountNo;
double savingBal= this.getSavingBal();
if (this.savingBal > amount)
{this.savingBal=-amount;
this.checkingBal=+amount;
}
else
{
System.out.println("Insufficent fonds into savings account");
}

}

public void setCheckingBal(double checkingBal) {
this.checkingBal = checkingBal;
}

public void setSavingBal(double savingBal) {
this.savingBal = savingBal;
}

public int getAccountNo() {
return accountNo;
}

public void setAccountNo(int accountNo) {
this.accountNo = accountNo;
}

public double getSavingBal() {
return this.savingBal;
}

public double getCheckingBal() {
return this.checkingBal;
}



}

最佳答案

this.savingBal=-amount;

应该是拼写错误

this.savingBal-=amount;

下一行有类似的拼写错误。这些可能会导致您的问题;如果不是,并且存在另一个问题,那么如果您解决了另一个问题,它们也会导致同样的问题。

关于Java实现储蓄账户到支票账户银行转账的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20315913/

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