BankAccount b0, b1, b2, b3;
b1=new BankAccount();
b2=new BankAccount();
b3=new BankAccount();
for (int i=0; i<3; i++)
{
if (i==0)
b0=b1;
else if (i==1)
b0=b2;
else
b0=b3;
和(你剛纔看到的是演示的一部分,下面是類的東西的一部分)toString方法不會打印出我的對象,而不是它的打印內存ADRESS
public String toString(double deposit, double withdraw, double fee, double total) {
String str=name+"'s bank account statement:" + "\nInitial balance: " + balance +
"\nDeposit amount: " + deposit + "\nWithdraw amount: " + withdraw + "\nNumber of transactions: "
+ transac + "\nTotal bank fees: " + fee + "Final monthly balance: " + total;
return str;
和(演示,我沒有包括所有的代碼,只因爲這仍然是一個開放的分配。
System.out.println(b0);
我真的不知道爲什麼它不打印字符串的東西:( 所有類(稍後會刪除)
public class BankAccount {
private String name;
private double balance;
private int transac;
public BankAccount() {
balance=0;
}
public void setName(String accountName) {
name=accountName;
}
public void setBalance(double accountBalance) {
balance=accountBalance;
}
public void setTransac(int accountTransac) {
transac=accountTransac;
}
public String getName() {
return name;
}
public double getBalance() {
return balance;
}
public int getTransac() {
return transac;
}
public double getDeposit(double deposit) {
return balance+deposit;
}
public double getWithdraw(double deposit, double withdraw) {
return balance+deposit-withdraw;
}
public double getFee(double fee, int accountTransac, double deposit, double withdraw) {
fee=10;
if (transac<20)
fee+=transac*0.5;
else if (20<=transac && accountTransac<40)
fee+=transac*0.25;
else if (40<=transac && transac<60)
fee+=transac*0.2;
else
fee+=transac*0.1;
if (balance+deposit-withdraw<400)
fee+=15;
return fee;
}
public double finalBalance(double fee, int accountTransac, double deposit, double withdraw) {
double total=balance+deposit-withdraw-fee;
return total;
}
public String toString(double deposit, double withdraw, double fee, double total) {
toString(this.deposit, this.withdraw, this.fee, this.total);
String str=name+"'s bank account statement:" + "\nInitial balance: " + balance +
"\nDeposit amount: " + deposit + "\nWithdraw amount: " + withdraw + "\nNumber of transactions: "
+ transac + "\nTotal bank fees: " + fee + "Final monthly balance: " + total;
return str;
}
}
toString shoud不接受任何參數 – Anton
^^ s/should/does/ –