Welcome to Dream.In.Code
Become a Java Expert!

Join 150,201 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,015 people online right now. Registration is fast and FREE... Join Now!




Making Change...

 
Reply to this topicStart new topic

Making Change..., need help with a concept.

alexgio
25 Sep, 2008 - 06:25 PM
Post #1

New D.I.C Head
*

Joined: 26 Mar, 2008
Posts: 11

OK I'm in my very first java programming class. My assignment is to create a program vendMachine.java basically we have to make a program that takes dollars and returns change for an item. Ive written out parts of the code but I'm so flipping confused i dont think Ill ever get this programming crap! Ive been at this for hours.

Anyway. my biggest problem is getting my program to compute change! I dont know how to approach this. any ideas? Here's what I've Got so far. I know its not much but please give me some startup advice as to how to compute change.

Thanks in advance.

PS. my professor says using the Modulous arithmetic operator will make this easier.

CODE
import javax.swing.JOptionPane;
public class vendMachine

{
            
    public static void main (String[] args)

    {    /*Below is the list of Variables used in this class.*/
            double dollar = 1.00;
            double quarter = 0.25;
            double dime = 0.10;
            double nickel = 0.05;
            double penny = 0.01;
            double Snickers = 0.34;
            double MilkyWay = 0.34;
            double AlmondJoy = 0.34;

        String snackString;
            
        JOptionPane.showMessageDialog (null, "This machine takes ONLY DOLLARS");
        
        snackString = JOptionPane.showInputDialog
        (null, "Type in your desired snack.\n    Snickers\n    MilkyWay\n    AlmondJoy",
         "Available Snacks", JOptionPane.INFORMATION_MESSAGE);

        JOptionPane.showMessageDialog (null, "Your total is 34 Cents");
        JOptionPane.showMessageDialog (null, "The number of Quarters is 2\nThe number of Dimes is 1\nThe number of nickles is 1\nThe number ofpennie's is 1");
    }    

}


User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Making Change...
25 Sep, 2008 - 06:32 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
The modulous (%) operator gives a remainder. This is important when calculating change since if you had: .35 to start .35%.25 = .10, thus you now know how much cannot be made with quarters alone. Hopefully this is enough to get you started.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:02AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month