I got stuck at this error:

cannot find symbol
symbol: variable BankAddress
location: class Bank
bankAddress = BankAddress;
<------pointing at BankAddress;


I'm trying to instantiate an object of Address, calling the constructor of the Address class to create an object of Address.


I'll post both classes, Bank and 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;

	}

}

Bank class

public class Bank
{
	private String bankName;
	private int bankID;
	private Address bankAddress;



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


	public Bank(String BankName, int anID, Address BankAddress)
	{
		bankName = BankName;
		bankID = anID;
		bankAddress = BankAddress;
	}

	public String getBankName()
	{
		return bankName;
	}

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

	public int getBankID()
	{
		return bankID;
	}

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

	public Address getBankAddress()
	{
		return bankAddress;
	}

	public void setBankAddress(String aCity, String aState)
	{
		bankAddress = BankAddress;
	}


	public String toString()
	{
		String result;
		result = "Bank name:\t\t" + bankName
		+ "Bank ID:\t\t" + bankID
		+ "Bank address:\t\t" + bankAddress;

		return result;
	}
}

I'm not sure what's wrong, I've been trying for the past hour now. It's so confusing.

Member Avatar for coil

I'd assume the error points to this method:

public void setBankAddress(String aCity, String aState)
{
	bankAddress = BankAddress; //Error here (?) - BankAddress does not exist
}

The reason is that BankAddress does not exist. It was created as a parameter for your constructor, but after your constructor is invoked, it is erased.

I think this is an accidental mistake. You're not using your parameters at all, so simply use (or create, if needed) a method in your Account class to modify the city and state.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.