我一直在研究这个小型的会计问题,在退出部分遇到一些问题。我需要帮助。
public class Account {
private double balance;
public Account (double initialBalance){
if(initialBalance > 0){
balance = initialBalance;
}
}
public double getDeposit(){
return balance;
}
public void credit (double amount){
balance += amount;
}
public double withdraw(double amount2){
//double amount1;
//double with;
if (balance > initialBalance){
balance - amount2;
}
答案 0 :(得分:4)
您需要在withdraw()
:
balance = balance - amount2;
或者这(相当于):
balance -= amount2;
否则,您将不会更新余额值
答案 1 :(得分:0)
你的问题是什么? 在撤回功能中不应该写你:
public double withdraw(double amount2){
if(amount2>0 && balance-amount2>0 /* or min acceptable deposit */){
balance-=amount2;
}
}