1

这是第一个文件,还有另一个文件可以真正解释我的问题;我的问题始于public Account getbankAddress()方法。

public class Bank {

    String bankName;
    int bankID;
    Address address = new Address();

    public Bank(){
        bankName = "?";
        bankID = 0;
    }

    public String getBankName(){
        return bankName;
    }

    public int getBankID(){
        return bankID;
    }

    public Address getBankAddress(){ 
        // This is where I'm having trouble getting the bank address from the address class,
        // How can I produce a result from the mutator method of setCity and setState methods?
        return address;
    }

    public void setBankName(String bankName1){
        bankName = bankName1;
    }

    public void setBankID(int ID){
        bankID = ID;
    }

    public void setBankAddress(String aCity, String aState){
        aCity = "city";
        aState = "state";
    }

    public String toString(){
        String str = ("\nBank name:\t\t" + bankName + "\nBank ID:\t\t" + bankID +
                "\nBank address:\t\t" + bankAddress + "\n\n");
        return str;
    }
}

public class Address{

    private String city;
    private String state;

    public Address(){
        city = "?";
        state = "?";
    }

    public String getCity(){
        return city;
    }

    public String getState(){
        return state;
    }

    public void setCity(String aCity){
        aCity = city;
    }

    public void setState(String aState){
        aState = state;
    }

    public String toString(){
        String str1 = (city + "," + state);
        return str1;
    }
}
4

1 回答 1

6

我认为改变这一点:

public void setBankAddress(String aCity, String aState){

aCity = "city";
aState = "state";

 }

public void setBankAddress(String aCity, String aState) {
  address.setCity(aCity);
  address.setState(aState);
}

应该管用。

++++++++++++++++++

另外,改变这个:

public void setCity(String aCity){
    aCity = city;
}

public void setState(String aState){
    aState = state;
}

public void setCity(String aCity){
    city = aCity;
}

public void setState(String aState){
    state = aState;
}
于 2013-09-06T09:41:50.240 回答