I'm writing two classes for the main program code. I'm stuck trying to do figure out how to instantiate an object of the class Address:


Address class:

public class Address
{
	private String city;
	private String state;


	public Address()
	{

	 city = "?";
	 state = "?";

	}

	public Address(String aCity, String aState)
	{

	 city = aCity;
	 state = aState;

	}

	public String getCity()
	{

	 return city;

	}

	public void setCity(String aCity)
	{

	 city = aCity;

	}

	public String getState()
	{

	 return state;

	}

	public void setState(String aState)
	{

	 state = aState;

	}

	public String toString()
	{

	 String result;
	 result = city + "," + state;
	 return result;

	}

}

The class I'm writing is called "Bank.java" There's three attributes:

bankName - String
bankID - int
bankAddress - Address (this one is linked to the Address class)

initialize them:

bankName = "?";

bankID = 0;

bankAddress = <-----(How do I do it for this one?) It asks me to instantiate an object of Address, calling the constructor of the Address class to create an object of Address

Thanks,


Danny N

I guess, in the Bank's constructor, the attribute "bankAddress" should be:

bankAddress = new Address();

Where is the code for the definition of Bank class?

Edited 6 Years Ago by tong1: n/a

The Bank class describes a bank that a customer can create an account. It must have the following attributes. Those attributes is what I mentioned above.

If you want to call your second constructor in the Address class you put in the names of the city and the state like in this example:
bankAddress = new Address(Vancouver, Canada);

Edited 6 Years Ago by sneaker: n/a

This article has been dead for over six months. Start a new discussion instead.