Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-22-2007, 03:56 AM
Member
 
Join Date: Nov 2007
Posts: 1
Francis is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-22-2007, 04:26 AM
Senior Member
 
Join Date: Nov 2007
Location: Newport, WA
Posts: 141
staykovmarin is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-22-2007, 03:03 PM
Member
 
Join Date: Nov 2007
Posts: 8
clement1 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing MIDlet for SMS - III JavaForums Java Blogs 0 04-11-2008 04:20 PM
Writing MIDlet for SMS - I JavaForums Java Blogs 0 04-09-2008 07:21 PM
How to execute an External Program through Java program Java Tip java.io 0 04-04-2008 03:40 PM
How to execute an External Program through Java program JavaBean Java Tips 0 10-04-2007 10:33 PM
writing to a excel file from java program priyankabhar New To Java 1 07-10-2007 09:05 PM


All times are GMT +3. The time now is 12:26 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org