I want to be able to give the program a number between 2 and 10 and it create that many objects from the same class in Java.
I'm not sure the best way to do this. The only way I can think of is that I make 10 if/else if statements and make the objects that way.
if (num == 2){
Class object1 = new Class(1)
Class object2 = new Class(2)
}
else if (num == 3){
Class object1 = new Class(1)
Class object2 = new Class(2)
Class object3 = new Class(3)
}
.
.
.
else if (num == 10){
Class object1 = new Class(1)
Class object2 = new Class(2)
Class object3 = new Class(3)
Class object4 = new Class(4)
Class object5 = new Class(5)
Class object6 = new Class(6)
Class object7 = new Class(7)
Class object8 = new Class(8)
Class object9 = new Class(9)
Class object10 = new Class(10)
}
Is there a better way to do this? I'm still learning to code so I'm not the best at it. Someone said something about an array of objects but I don't know what that is or if it relates to this problem. Thank you.