Hi I'm using a 2d array to simulate a vending machine.
I want to declare an array with a set length and make it oversize so it can accommodate me adding items to it.
Ex:
String[][] itemsT1 = new String[][] {null, null, null, null, null, null, null, null, null};
int itemCount = 0;
// The way I've been adding things in my "addItem' method is:
if ( (items.length > 0) && (itemsCount < items.length) ) {
items[itemsCount][0] = nameOfItem;
items[itemsCount][1] = expirationDate;
itemsCount++;
System.out.println("Item added");
}
// so that the end result of the array should be (with nameOfItem = "Water" and expDate = "15") something like this:
{ {"Water", "15"}, null, null, null, null, null, null, null, null}
// and it's scalable to be hypothetically used again:
{ {"Water", "15"}, {"Chocolate", "20"}, {"Juice", "25"}, null, null, null, null, null, null}
I might be back with more questions so thank you for answering, and let me know if I need to provide more!