Objects within classes
Hi, I haven't programmed in Java for four years, but I have a project that is forcing me to get back into it.
Essentially, I am simulating an artifical world. I have a class called 'State' and it needs to have a Vector 'allies.'
I can't figure out how to instantiate State and make this Vector not be null. I've tracked it down and I am sure that when 'allies' is used, it comes back null.
I have tried a number of different things, but I just can't get the Vector to not be null.
I pasted to source code for the class below.
Thanks,
Andy
public class State {
// fields
public int power;
public double aggressiveness;
public double threatTolerance;
public boolean independent;
public Vector allies;
// constructor
public State(int startPower, double startAggressiveness, double startThreatTol) {
power = startPower;
aggressiveness = startAggressiveness;
threatTolerance = startThreatTol;
independent = true; // all states begin independent
Vector allies = new Vector();
Coordinates dummy = new Coordinates(-1, -1);
Ally dummyA = new Ally(dummy, dummy);
allies.addElement(dummyA);
//allies.removeAllElements(); // states start with no allies
}
// methods
public void addAlly(Ally newAlly){
allies.addElement(newAlly);
}
}

