Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Java Vending Machine Program

I'm trying to write a vending machine program so far I've been able to do everything except add drinks.

public class VM{

public VM(int price)
{
Cost= Price;
String vend [][] = new String [2][2];
drinks= new ArrayList();
}

}

I'm trying to write addDrink() method, but have not been able to.

I'm trying to use something like drink.add(new vend(Drink_variable)), but haven't been able to. I've been reading many books but all the examples there write something else. e.g.drink.add(new vend(price p)).

Its driving me mad. I have no where to turn to. Reading books are not helping. I have no one I can ask help for. People just don't care. Probably this post that I'm writing right now will be of no use, since I won't get any useful feedback. It's easy to say write a for loop, declare an object, write a class for this or that. But I haven't been able to implement this. If I could see at least a similar example may I can learn something.

I don't know how I can add an item to an array. So everytime I call the addDrink method the list of Drinks in the array should increase. So when I display them I can see a list of the drinks I've added. And also, I should be able to determine its price and slot(eg A1) when adding.

If someone can write an example of just the add method to a vending machine that will be very helpful.

I can send you the full code that I have done so far if you want.

I would appreciate any feedback.

Regards,

John
[1632 byte] By [JohnSmith70] at [2007-11-11 11:58:20]
# 1 Re: Java Vending Machine Program
How are you representing the drink objects? I assume you would have an instance of a class or a structure which has a price and slot component

Use a vector rather than an array for each of your slots ... it grows ... you can query its size, you can use the Vector class' add and remove methods, etc.
nspils at 2007-11-11 22:30:24 >