求大佬帮助,为什么我在执行添加帐户之后程序运行输出的是哈希码,而不是账户的信息呢?类中我是有重写toString方法的
package com.mybank.domain;
public class Account {
private double balance;
public void initBalance(double balance) {
this.balance = balance;
}
public boolean deposit(double amt) {
if(amt > 0) {
balance +=amt;
return true;}
else
return false;
}
public boolean withdraw(double amt) {
if(amt > balance) {
System.out.println("余额不足!");
return false;
}
else
balance -= amt;
System.out.println("取钱成功!");
return true;
}
public double getBalance() {
return balance;
}
}
package com.mybank.domain;
public class Customer {
private String firstName;
private String lastName;
private Account accounts[];
private int numberOfAccounts;
public Customer(String firstName,String lastName) {
this.firstName = firstName;
this.lastName = lastName;
accounts = new Account[10];
numberOfAccounts = 0;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public void addAccount(double amt) {
Account account = new Account();
account.initBalance(amt);
accounts[numberOfAccounts++] = account;
}
public int getNumberOfAccounts() {
return numberOfAccounts;
}
public Account getAccount(int index) {
return accounts[index];
}
public String toString() {
return firstName+" "+lastName;
}
}
package com.mybank.domain;
public class Bank {
public static Customer[] customers;
private static int numberOfCustomers;
static {
customers = new Customer[10];
numberOfCustomers = 0;
}
public static void addCustomer(String firstName,String lastName) {
Customer customer = new Customer(firstName,lastName);
customers[numberOfCustomers++] = customer;
}
public static int getNumberOfCustomers() {
return numberOfCustomers;
}
static Customer getCustomer(int i) {
return customers[i];
}
}
package com.mybank.test;
import com.mybank.domain.Bank;
public class TestBanking {
public static void main(String[] args) {
Bank.addCustomer("Wang","Ling");
Bank.customers[0].addAccount(500);
Bank.customers[0].addAccount(1000);
Bank.customers[0].addAccount(1500);
for(int i=0; i<Bank.getNumberOfCustomers();i++) {
Bank.customers[i].toString();
for(int j=0; j<Bank.customers[i].getNumberOfAccounts(); j++) {
System.out.println(Bank.customers[i].getAccount(j));
}
}
}
}