所以在我的 Java 课程作业中,我们必须修改一个类,然后在 Jgrasp 中编写一个测试器类,我的测试器类看起来像这样
public class BankAccountTester {
public static void main(String[]args){
BankAccount account = new BankAccount(1000);
account.setFreeTrans(5);
account.setTransFee(2);
account.deposit(1000);
account.withdraw(500);
account.withdraw(400);
account.deposit(200);
System.out.println(account.getBalance());
System.out.println("expected: 1300");
account.monthlyCharge();
System.out.println(account.getBalance());
System.out.println("expected: 1300");
account.deposit(1000);
account.withdraw(500);
account.withdraw(400);
account.deposit(500);
System.out.println(account.getBalance());
System.out.println("expected: 1900");
account.monthlyCharge();
System.out.println(account.getBalance());
System.out.println("expected: 1900");
account.deposit(1000);
account.withdraw(500);
account.withdraw(400);
account.deposit(200);
account.deposit(500);
account.withdraw(1000);
System.out.println(account.getBalance());
System.out.println("expected 1700");
account.monthlyCharge();
System.out.println(account.getBalance());
System.out.println("expected 1698");
account.deposit(1000);
account.withdraw(500);
account.withdraw(400);
account.deposit(200);
account.deposit(500);
account.withdraw(1000);
account.deposit(100);
System.out.println(account.getBalance());
System.out.println("expected 1598");
account.monthlyCharge();
System.out.println(account.getBalance());
System.out.println("expected 1594");
}
}
所以我遇到的问题是它没有打印出我编程打印出来的所有值,它应该打印出看起来像这样的东西:
1300
expected: 1300
1300
expected 1300
1900
expected 1900
1900
expected 1900
1700
expected 1700
1698
expected 1698
1598
expected 1598
1594
expected 1594
但相反,我得到的是:
1300.0
expected: 1300
1300.0
expected: 1300
1900.0
expected: 1900
1900.0
expected: 1900
有人知道这是什么吗,因为我无法弄清楚它会这样做的原因。请注意,此测试是在 JGrasp 的工作台上完成的。谢谢