//Creates a variable called product that stores the item we have selected
for(inti=0;i<5;++i){
for(intj=0;j<4;++j){
//for loop to find the product name in the 2D array
if(VendingItems[i][j]==product)
//if the product name in the 2D array equals to the prooduct name selected
{
if("Chocolate".equals(product)){
//if the product selected is Chocolate
if((int)VendingItems[i][j+2]>quantc){
//This searches the quantity in the array of the specific product and searches if it's greater of quantc which is now set to 0
quantc+=1;
//ads one to quantc since we have slected one chocolate
SelectedProducts.append(product+"\n");
//prints the selected product to the text area, /n creates a new lie
cost+=(double)VendingItems[i][j+1];
// this changes the string called cost to the variable inside the 2D array, it searches it by the specific product and adding one to j because of the position
TotalCost.setText("Total Cost (£) - "+cost);
//Modifies the lable called Total Cost to show the cost of the overall products.
//once all the possible items have been approved and the user has inputed the correct amount the program prints that the user can collect their products