DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2007

    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.



  2. #2
    Join Date
    Dec 2004
    San Bernardino County, California
    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

  1. Replies: 0
    Last Post: 11-24-2006, 07:11 AM
  2. Replies: 1
    Last Post: 06-12-2006, 11:20 AM
  3. menu-driven java program (help please)
    By emasha in forum Java
    Replies: 2
    Last Post: 04-30-2006, 09:08 AM
  4. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  5. Has Sun Given Up on the Desktop?
    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
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.