As an exercise (note that I am a programming student, but this is an exercise to satisfy my own curiosity, not for a graded assignment) in using instance variables, I would like to create an unspecified number of instances of a class and assign a unique name to each. My idea would be to make a loop such as:
int i=1;
while (! response.equals("quit")){
SomeClass object_i = new SomeClass();
i++;
...
}
This would allow the program to create as many instances of SomeClass as needed by the user, then be able to refer back to instance variables in each one such as:
for (i=1; i <= count; i++){
sum += object_i.nonStaticInstanceVariable;
}
There is a suggestion for unique identifier names using AtomicLong at this thread: java for loop executes too fast gives System.currentTimeMillis() duplicate
but I am unsure of how I would refer to instance variables in particular objects created using this method. Can anybody suggest a way to do what I'm trying to do in Java?
Many thanks.