Results 1 to 3 of 3
  1. #1
    Francis is offline Member
    Join Date
    Nov 2007
    Rep Power

    Default Help needed writing a program...

    Hi everyOne,

    I m trying 2 write a program for a Vending machine. The main purpose of the machine is to accept coins (1pound, 50 pence, and 20 pence) from a customer and dispense the item. I have two questions regarding this example;

    Question 1: If I need to write a method to accept coins (mentioned above) from a customer, and then write a function of the total money inserted; How could I output total money inserted by a customer as pounds & pence, e.g. (1.70). I have been using double to declare coin variable but when I output the result it shows as 1.7. Eliminating the last 0 in the end.

    Question 2: My second question is about the same java program 'vending machine. If I need to write a 'cancel' method for a vending machine class, which should refund all coins inserted by a customer (taking in to consideration that customer has not spend any amount, all they wants their coins back). How can I implement this method?



  2. #2
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Newport, WA
    Rep Power


    Java Code:
    		DecimalFormat form = new DecimalFormat("#.00");
    		double d = 1.70;
    You could have a variable that stores how much they have entered, and just give them that much money back?

  3. #3
    clement1 is offline Member
    Join Date
    Nov 2007
    Rep Power


    you could store the coins entered in an array then when the 'cancel' option is used, youjust search through the array and add up the coins and display it back to the user.

Similar Threads

  1. writing to a excel file from java program
    By priyankabhar in forum New To Java
    Replies: 15
    Last Post: 01-17-2014, 01:39 PM
  2. Replies: 0
    Last Post: 04-04-2008, 03:40 PM
  3. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts