[Off-topic] slow_DC4:
Hi, sadly, it's me again seeking for some help.

This is what we are supposed to do

In this assignment you will use the techniques you used in lab to create an interactive vending machine. You must use Arraylists to store the information about the items for sale in the machine. Use the class you created in Assignment 5 in your ArrayLists.

Only the first item in a slot can be sold.

Hint:

Declaring and ArrayList of ArrayLists

Where Type is your class:

ArrayList<ArrayList<Type>> array;

You must also add each ArrayList to the ArrayList

array.add(new ArrayList<Type>());

End Hint

All Methods listed should be public:

Items will follow the restrictions delineated in Assignment 5. (You should leverage the abilities built into that class)

You will create a VendingMachine class that has at least the following methods:

VendingMachine(int numSlots, int maxItems)

This constructor will set up the object so that numSlots is the number of slots the machine has. MaxItems will be the maximum number of items that can be placed in each slot.

void menu()

This method will print a list of the items available, their price and the slot it is in. Only the first item in a slot will be printed. If a slot is Empty “Empty” should be printed with $0.00 for the price. Will also print out the current amount held in the machine.

boolean load(int slotNum, String name, double price, int quantity)

This method will load items into the machine. slotNum will be the slot that the items will be placed in, name will be the name of the item in the machine and price the price. Quantity is the number of this item that should be added. If the quantity exceeds the current capacity of the slot it should add nothing to the slot and return false. If the loading is successful return true.

int capacity(int slotNum)

returns the number of spaces empty in the slot specified.

void insertMoney( double money)

Will increase the amount of money in the machine by the amount of money (will not do anything if money is negative)

double returnMoney()

Will set amount of money in the machine to 0 and return the amount that was in the machine.

boolean select(int slotNumber)

Attempts to purchase the item in the slotnumber selected it returns true if the sale was successful and false if it was not. For a successful sale the amount held in the machine must be greater than the selected item. There must also be a valid item to be sold (the slot is not empty). If the item is sold the amount in the machine should be decreased by the price of the item. The first items in the slot should be removed.

This is what I have:

import java.util.ArrayList;

class itemVend{

public String item;
public double price;
final double maxPrice=99.99;

public itemVend(String item, double price){
this.item=item;
this.price=price;
}

public String getItem(){
if (item.length()>20){
item=item.substring(0,20);
}
System.out.println(item);
return item;
}

public double getPrice(){

if (price>=100.00){
price=99.99;
}

String priceNormal=String.format("%.2f",price);
System.out.format("$%5s",priceNormal);
double nPrice=Double.valueOf(priceNormal);
return nPrice;
}
}

class VendingMachine{
int numSlots;
int maxItems;
int slotNum;
String name;
double price;
int quantity;
double total;
double money;
int [] NumSlot=new int[numSlots];
int [] SlotAdd=new int [maxItems];

ArrayList<ArrayList<VendingMachine>> VendM;

public VendingMachine(int numSlots, int maxItems){
this.numSlots=numSlots;
this.maxItems=maxItems;
}
/*
public void menu(){
for (int x=0;x<numSlots;x++){
System.out.print(NumSlot[x]+","+name+","+price);

}
}
*/
public boolean load (int slotNum, String name, double price,int quantity){
if (quantity<=maxItems){
this.slotNum=slotNum;
this.name=name;
this.price=price;
itemVend IV=new itemVend(name,price);
this.quantity=quantity;
return true;
}
else {
return false;
}
}

public int capacity (int slotNum){
int emptySpace=maxItems-quantity;
return emptySpace;
}

public void insertMoney (double money){
total=total+money;
}

public boolean select(int slotNum){
if ((money>price)){
total=total-price;
return true;
}
else {
return false;
}
}
}

It's not quite done yet, and I'm sure that I have a lot of errors, because I am getting a little frustrated. The parts that I am having the most difficulty with is the VendingMachine constructor and the printing of the menu. Also I don't understand how the hint applies.

I think I may have figured out the menu problem:

public void menu(){
for (int x=0;x<VendNumber.size();x++){
System.out.println("Slot number: "+VendNumber.get(x)+", Item Name: "+VendItemName.get(x)+", Item Price: $"+ItemPrice.get(x));

}
}

Assignment 5 refers to the itemVend class.

Thanks in advance.