So I have this code,
Which is useful if I want to create a VendingMachine object of 10 Dispenser objects (which is an arrayList of FoodInfo obejcts) of the SAME type of object. This would be great if I wanted a vending machine that only sells cokes....
I was kind of stumped on what the best way to put in multiple FoodInfo objects. What I want to have is to have a Vending Machine where each of the 10 dispensers is a different type of food or drink. I was going to go the simple route and just manually insert item1 - item10 in the constructor and the same for each Dispenser but that doesn't seem like it would be the most efficient or best way to do so.
Can anyone give me any other ideas? I'm having trouble putting together a for loop that could do it which was really the only way I can think besides the manual way mentioned above...
public VendingMachine(String machineName, FoodInfo item) {
this.machineName = machineName;
item1 = item;
for (int i = 0; i < 10; i++) {
dispArray[i] = new Dispenser(item);
}
}
Which is useful if I want to create a VendingMachine object of 10 Dispenser objects (which is an arrayList of FoodInfo obejcts) of the SAME type of object. This would be great if I wanted a vending machine that only sells cokes....
I was kind of stumped on what the best way to put in multiple FoodInfo objects. What I want to have is to have a Vending Machine where each of the 10 dispensers is a different type of food or drink. I was going to go the simple route and just manually insert item1 - item10 in the constructor and the same for each Dispenser but that doesn't seem like it would be the most efficient or best way to do so.
Can anyone give me any other ideas? I'm having trouble putting together a for loop that could do it which was really the only way I can think besides the manual way mentioned above...