Hello,
i need help on who to create multiple objects
i provide a part of the code, what i need is to create, for example, 25 Cartons.
How can i implement this faster (?) without writing 25 times :
"
Carton carton1 = new Carton(numBags);
Carton carton2 = new Carton(numBags);
Carton carton1 = new Carton(numBags);
....
Carton carton25 = new Carton(numBags);
"
public class Programm{ protected int numCartons; //number of Cartons. 25 cartons protected int numBags; //number of Bags in Cartons. 2 bags per carton public Programm(int numCartons, int numBags){ this.numCartons= numCartons; this.numBags = numBags; } public void createCartonsWithBags(int numBags){ Carton carton1 = new Carton(numBags); Carton carton2 = new Carton(numBags); Carton carton3 = new Carton(numBags); //.... Carton carton25 = new Carton(numBags); } public static void main(String[] argv ){ int numCartons = 25; int numBags= 2; Myprogram m = new Myprogram(numCartons , numBags); m.createCartonsWithBags(numCartons); } }