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

    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?

    Thanks,

    Francis

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

    Default

    Java Code:
    		DecimalFormat form = new DecimalFormat("#.00");
    		double d = 1.70;
    		System.out.println(form.format(d));
    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
    Posts
    8
    Rep Power
    0

    Default

    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, 12:39 PM
  2. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  3. Replies: 0
    Last Post: 10-04-2007, 09: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
  •