我在Account Class中有以下方法
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;
}
}
答案 0 :(得分:3)
this.savingBal=-amount;
应该是
的拼写错误this.savingBal-=amount;
下一行有类似的错字。这些可能会导致你的问题;如果它们不存在并且存在另一个问题,如果您修复了另一个问题,它们将导致同样的问题。