-1
private State USA = new State("United States of America");
private State CAN = new State("Canada");
private State MEX = new State("Mexico");
private State[] stateArray;
public static void main()
{
}


public void addState(State state) //I need a way to add the Private objects called State into an array here. The command must take User Interface
{
    stateArray = stateArray.add(state);
}

要約すると、addState 配列に見られるように、配列に項目を追加できる何らかのメソッドが必要なだけです。

4

2 に答える 2

0

配列を使用する場合:

private State USA = new State("United States of America");
    private State CAN = new State("Canada");
    private State MEX = new State("Mexico");
    private State[] stateArray = new State[3];
    int index = 0;
    public static void main()
    {
    }


    public void addState(State state) //I need a way to add the Private objects called State into an array here. The command must take User Interface
    {
       if(index < stateArray.length)
           stateArray[index++] = state;
    }

ArrayListまたは、代わりに配列を使用できます。

private State USA = new State("United States of America");
    private State CAN = new State("Canada");
    private State MEX = new State("Mexico");
    private ArrayList<State> stateArray = new ArrayList<State>;
    public static void main()
    {
    }


    public void addState(State state) //I need a way to add the Private objects called State into an array here. The command must take User Interface
    {
        stateArray.add(state);
    }
于 2013-04-14T03:02:59.503 に答える