-
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.
Code:
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
-
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.
Similar Threads
-
By balaji krishna in forum Database
Replies: 0
Last Post: 11-24-2006, 07:11 AM
-
Replies: 1
Last Post: 06-12-2006, 11:20 AM
-
Replies: 2
Last Post: 04-30-2006, 09:08 AM
-
Replies: 1
Last Post: 05-13-2005, 06:46 AM
-
By Lori Piquet in forum Talk to the Editors
Replies: 114
Last Post: 10-10-2002, 06:01 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks