Daniel Ray
Posts: 53
Nickname: budoray
Registered: Oct, 2002
|
|
Re: classes and arrays
|
Posted: Nov 21, 2002 8:41 PM
|
|
Try it this way. Two public classes here .. so choose how you want to handle that .. make one an inner class or just separate them in different files.
public class Name { private int id;
public Name() {
}// End Name()
public void setId(int id){ this.id = id;
}// End setId(int)
public int getId(){ return id;
}// End getId()
}// End class Name
public class TestName { private Name[][] myName;
public TestName() { myName = new Name[5][5];
}// End TestName()
public void populateMyName(){ int count = 0;
for(int i=0; i<5; i++){ for(int j=0; j<5; j++){ Name newName = new Name(); newName.setId(++count); myName[j] = newName;
}
}
}// End populateMyName()
public void printMyNameIds(){ Name tempName;
for(int i=0; i<5; i++){ for(int j=0; j<5; j++){ tempName = myName[j]; System.out.println("ID = " + tempName.getId());
}
}
}// End printMyNameIds()
public static void main(String[] args) { TestName testName = new TestName();
testName.populateMyName(); testName.printMyNameIds();
}// End main(String[])
}// End class TestName
Ray
|
|