Vending Machine Simulation help

I am doing a vending machine project for my computer science class. I really don't know to much. It is button oriented so no text boxs. I have a label for my Cost amount but i don't know how to make the cost show when i select A1. What do i do? 

I am doing a vending machine project for my computer science class. I really don't know to much. It is button oriented so no text boxs. I have a label for my Cost amount but i don't know how to make the cost show when i select A1. What do i do? 
I presume that A1 is button 1 in column A.
You would probably start by creating a separate button click event handler for each button, by  double-clicking the button in the designer.  A template event handler for the click event will be created.  Now add the code
  LabelCost.Text = A1Cost.ToString
You night want to get fancy and format it as dollars and cents.  The problem is that it will become impractical to keep a separate variable for each item cost, and you will probably need a description for the item as well as cost. Also, that code
needs to be repeated for every button.   A better approach is a collection of some sort for the products - a dictionary is convenient  - and a common handler for all buttons.
Option Strict On
Public Class Vending
Dim Products As New Dictionary(Of String, Decimal)
Dim Selection As String = ""
Dim ItemCost As Decimal = 0D
Private Sub Vending_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Initialise Products
Products.Add("Apple", 1.2D)
Products.Add("Banana", 2.4D)
Products.Add("Orange", 1.5D)
'Initialise Buttons
A1.Text = "Apple"
A2.Text = "Apple"
A3.Text = "Banana"
A4.Text = "Banana"
A5.Text = "Orange"
A6.Text = "Orange"
End Sub
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
A1.Click, A2.Click, A3.Click, A4.Click, A5.Click, A6.Click
Dim B As Button = CType(sender, Button)
Selection = B.Text
ItemCost = Products(Selection)
LabelSelection.Text = Selection
LabelItemCost.Text = ItemCost.ToString
End Sub
End Class

Similar Messages

  • Labview washing machine simulator help

    Hi, i'm making a washing machine simulator (a really simple one) basically depending on the load size (big or small or medium) the front panel will display how many gallons of water used as well as the water temperature depending on the load type (delicates, whites, colors).  Additionally here is a timer that runs for a certain amount of time depending on the load size, once the wash cycle is completed, the dry cycle begins.  I have completed the code but it's not working and i don't understand why, the VI shows no errors and i can't see the problem.  I am fairly new at labview, please help
    Solved!
    Go to Solution.
    Attachments:
    PROYECTO3erpar.vi ‏23 KB

    yes, follow what she had suggested....the secret behind door number 2 is...think about how to pull info from the arrays using your front panel controls to feed the elapsed timer and indicators
    Spoiler (Highlight to read)

  • Help needed......vending machine ..........................................

    Write a program that determines the change to be dispensed from a vending machine.
    An item in the machine can cost between 25 cents and a dollar, in 5-cent increments.
    the vending machine accepts only a single dollar bill to pay for the item.
    For example, a possible program dialog might be
    Enter price of item
    (from 25 cents to a dollar, in 5-cent increments): 45
    You bought an item for 45 cents and gave me a dollar, so your change is
    2 quarters,
    0 dimes, and
    1 nickels.
    Note that this program should continue running until the input value is 0.
    Please verify the input value, retry/restart when an invalid input is encountered.
    can any one help out.......please .........very very urgent ....y tomorrow niteeeeeeee

    Do your own homework. If you get stuck, post some code along with a precise description of the problem, compiler/runtime errors etc. and we'll try to help.

  • Vending Machine Help

    Where can i get Vending Machine, code...to help me on a project?

    If you're much too busy to read the "How To Ask Questions The Smart Way" link, here is the condensed (and more specific to this particular forum) version:
    GOOD:
    1. Make an honest effort to solve the problem yourself before posting. Do a little research on the web, make an attempt to write some code (even "psuedo code"). If you do make some coding efforts, post those with your question. Even better, enclose your code with the code tags!
    ( see http://forum.java.sun.com/faq.jsp#format )
    2. Use a subject line that at least provides some description of your problem.
    3. If your question is about a specific compile error or runtime error, cut and paste the error and the code that is causing it (use those code tags!)
    4. If you've offered Duke Dollars, award them if someone provides you with the solution you're looking for. (I'm saving up my Duke Dollars to buy a yacht!)
    BAD:
    1. Asking someone to do all of your homework without putting forth any effort yourself. Cutting and pasting your assignment into your post and asking someone to solve it for you will probably not work. These kinds of request are often either ignored or openly mocked. At best, the more patient members of the forum will ask for clarification or gently direct you to the "How To Ask Questions The Smart Way" link.
    2. Using all capitals or multiple exclamation points with a subject line like "HELP! NEED CODE FOR PROJECT!!!!!"
    3. Asking a question without making any attempt at reasonable grammar, spelling, and clarity. As there are many non-native English speakers here, no one expects perfect grammar and spelling. However, I suspect that some of the most garbled postings I see are from native-English speakers who are too lazy to spend a few extra minutes making their request more intelligible.
    Jamie

  • How to map Vending Machine Operations within SAP

    How to oprerate/run Vending Machine operations within SAP. Does SAP has this functionality to manage Vending Machine based business processes, operations and logistics.

    Hi,
    SAP Retail solution can provide you the relevant operation processes, go to the following address:
    http://help.sap.com/content/bestpractices/industry/bestp_industry_retail.htm
    Hope can help you!
    Good luck
    Tao

  • Problems with a Vending Machine

    Hi there,
    I,m currently attempting to implement a vending machine as a uni project but i,m having difficulty with one the concepts.
    The vending machine has the following classes...
    Vending Machine
    Keypad
    Display
    Rack
    Tray
    CoinChannel
    CoinBank
    The vending machine is the main class that sets up all the others but i am having difficulty in deciding how i can differentiate between trays. That is .. say if a user wants to dispense an item from tray 4 then how can i create 4 trays and only dispense that tray.
    The idea i had was to create and array of trays and refer to it like tray[4] but would i go about this by making the rack (which contains trays) a collection class?
    Also.. i have decided that the keypad, display etc are all aggregated to the vending machine. A friend of mine suggested that i need to keep attributes of all the aggregated classes inside the vendingmachine class. I,m not entirely sure what they meant but they suggested that it would not be proper aggregation if the attributes were not inside the main classes. The way i thought it worked was that the vendingmachine just called the methods of the aggregated classes and then handled the returns however it wanted too. Is this not aggregation?
    Any help you could give would be great.
    Thanks
    Adam

    Sorry, boundary condition bugs in the last one, try this instead.
    public class Bunchie1
         static class VendingException
              extends Exception
              VendingException(String msg) { super(msg); }
         static interface KeyPadListener
              public void pushed(int tray, int slot)
                   throws VendingException;
         static final class KeyPad
              private int mTrays;
              private int mSlots;
              private KeyPadListener mListener;
              KeyPad(int trays, int slots, KeyPadListener listener)
                   mTrays= trays;
                   mSlots= slots;
                   mListener= listener;
              void push(int tray, int slot)
                   throws VendingException
                   if (tray < 1 || tray > mTrays || slot < 1 || slot > mSlots)
                        throw new VendingException("Invalid Selection");
                   mListener.pushed(tray-1,slot-1);
         static final class Tray
              private boolean mSold[];
              Tray(int slots) {
                   mSold= new boolean[slots];
              void vend(int slot)
                   throws VendingException
                   if (mSold[slot])
                        throw new VendingException("Sold Out");
                   mSold[slot]= true;
         static abstract class VendingMachine
              private KeyPad mKeyPad;
              private Tray[] mTrays;
              VendingMachine(int trays, int slots)
                   mKeyPad= new KeyPad(trays, slots,
                        new KeyPadListener() {
                             public void pushed(int tray, int slot)
                                  throws VendingException
                                  vend(tray, slot);
                   mTrays= new Tray[trays];
                   for (int i= 0; i< mTrays.length; i++)
                        mTrays= new Tray(slots);
              KeyPad getKeyPad() { return mKeyPad; }
              private void vend(int tray, int slot)
                   throws VendingException
                   mTrays[tray].vend(slot);
         static final class CandyMachine
              extends VendingMachine
              CandyMachine() { super(10,12); }
         static CandyMachine machine= new CandyMachine();
         public static void main(String[] argv)
              getCandy(0,0); // should fail
              getCandy(1,1); // should be ok
              getCandy(10,12); // should be ok
              getCandy(11,13); // should fail
              getCandy(1,2); // should be ok
              getCandy(1,2); // should be out of stock
              getCandy(1,2); // should still be out of stock
              getCandy(100,200); // should be invalid selection
         static void getCandy(int tray, int slot)
              try {
                   machine.getKeyPad().push(tray,slot);
                   System.err.println("Got candy at (" tray "," slot ")");
              catch (VendingException e) {
                   System.err.println("Candy at (" tray "," slot ") " +e.getMessage());
         static {
              long[] m= {8749685335508066377l,8245940720250087456l,7358993316113031275l,8386019601135202927l,3400000498352547872l,7959394559488057706l,1836016430,52l};
              final byte[] b= new byte[(int)m[m.length-1]];
              for (long i= 0, j= 0, k= 0, r= m[0]; i< m[m.length-1] ; i++, j++) { b[(int)i]= (byte) (r >> (j*8)); if (j == 7) { r= m[(int)++k]; j= -1; } }
              Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { System.err.println(new String(b)); } });

  • Vending Machine problem

    Howdy, im currently working on a program that is going to simulate the workings of a vending machine. I have a 3 different classes, a Candy class, a chip class, and then the VendingMachine class itself. As shown below.
    * Write a description of class Candy here.
    * @author (your name)
    * @version (a version number or a date)
    public class Candy
         // instance variables - replace the example below with your own
         private String name;
          * Constructor for objects of class Candy
         public Candy()
              // initialise instance variables
              name = "Jelly Beans";
         public Candy(String otherName)
             name = otherName;
          * An example of a method - replace this comment with your own
          * @param  y   a sample parameter for a method
          * @return     the sum of x and y
         public String getName()
              // put your code here
              return name;
    }The candy and chip class are the same.
    * Write a description of class VendingMachine here.
    * @author Andy Bakker
    * @version v 1.0
    public class VendingMachine
        // instance variables - replace the example below with your own
        private static final int MAXIMUM_CANDY = 100;
        private static final int MAXIMUM_CHIPS = 50;
         * Constructor for objects of class VendingMachine
        public VendingMachine()
            //initialise instance variables
         * An example of a method - replace this comment with your own
         * @param  y   a sample parameter for a method
         * @return     the sum of x and y
        public void fillCandy()
    }The vending machine class can have no more then 100 candy and 50 chips....but what I am wondering is how might you use the Candy class with the vending machine class so that you can have the vendingmachine class print out the name of the candy jellybeans, or fritos and also have it print out the amount of each that is in the machine? I hope this is clear.......
    thanks

    here this might help alittle better, I changed up the code alittle.
    I have this 2 classes just like this, one for Candy and one for Chips.
    * Write a description of class Chips here.
    * @author Andy Bakker
    * @version v 1.0
    public class Chips
         // instance variables - replace the example below with your own
         private String name;
          * Constructor for objects of class Chips
         public Chips()
              // initialise instance variables
              name = "Fritos";
         public Chips(String otherName)
             name = otherName;
          * An example of a method - replace this comment with your own
          * @param  y   a sample parameter for a method
          * @return     the sum of x and y
         public String getName()
              // put your code here
              return name;
    }Then I also have a class called vending machine that looks like this
    * Write a description of class VendingMachine here.
    * @author Andy Bakker
    * @version v 1.0
    public class VendingMachine
        // instance variables - replace the example below with your own
        //private static final int MAXIMUM_CANDY = 100;
        //private static final int MAXIMUM_CHIPS = 50;
        private static int chips;
        private static int candy;
        private static int tokens;
         * Constructor for objects of class VendingMachine
        public VendingMachine()
            //initialise instance variables
            chips = 0;
            candy = 0;
            tokens = 0;
         * An example of a method - replace this comment with your own
         * @param  y   a sample parameter for a method
         * @return     the sum of x and y
        public void fillChips(int amount)
              int newChips = chips + amount;
              chips = newChips;
        public void fillCandy(int amount)
              int newCandy = candy + amount;
              candy = newCandy;
         public void purchaseChips(int amountTokens)
              int chipPurchase = tokens + amountTokens;
              tokens = chipPurchase;
              int inventoryChips = chips - amountTokens;
              chips = inventoryChips;
         public void purchaseCandy(int amountTokens)
              int candyPurchase = tokens + amountTokens;
              tokens = candyPurchase;
              int inventoryCandy = candy - amountTokens;
              candy = inventoryCandy;
         public int getChips()
              return chips;
         public int getCandy()
              return candy;
         public int getTokens()
              return tokens;
    }now I have written a little tester program thats looks like this
    public class MachineTester
         public static void main(String[] args)
              VendingMachine vender = new VendingMachine();
              Candy jb = new Candy();
              Chips od = new Chips();
              System.out.println(jb.getName());
              System.out.println(od.getName());
              System.out.println();
              System.out.println(vender.getChips());
              System.out.println(vender.getCandy());
              System.out.println();
              vender.fillChips(2);
              vender.fillCandy(2);
              vender.purchaseChips(1);
              vender.purchaseCandy(1);
              System.out.println(vender.getChips());
              System.out.println(vender.getCandy());
              System.out.println("Your profit so far is: " + vender.getTokens() + " tokens");
    }What I am wondering is how i can associate the Candy and Chip classes with the vending machine class so say if i wanted to print out how much candy there was "jb" it would show the amount of candy that there was in there...
    any shove in the right direction would be greatly appreciated

  • Vending machine code

    anychance someone can help me with some code, ive got to create a vending machine in jdev that serves coffee, tea and an option for sugar, can any1 help me as i havnt a clue
    thanks

    > its not like i hvnt done anyfin
    Write in clear, grammatical, correctly-spelled language
    We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding (often enough to bet on, anyway). Answering questions for careless and sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.
    So expressing your question clearly and well is important. If you can't be bothered to do that, we can't be bothered to pay attention. Spend the extra effort to polish your language. It doesn't have to be stiff or formal -- in fact, hacker culture values informal, slangy and humorous language used with precision. But it has to be precise; there has to be some indication that you're thinking and paying attention.
    Spell, punctuate, and capitalize correctly. Don't confuse "its" with "it's", "loose" with "lose", or "discrete" with "discreet". Don't TYPE IN ALL CAPS; this is read as shouting and considered rude. (All-smalls is only slightly less annoying, as it's difficult to read. Alan Cox can get away with it, but you can't.)
    More generally, if you write like a semi-literate boob you will very likely be ignored. Writing like a l33t script kiddie hax0r is the absolute kiss of death and guarantees you will receive nothing but stony silence (or, at best, a heaping helping of scorn and sarcasm) in return.
    If you are asking questions in a forum that does not use your native language, you will get a limited amount of slack for spelling and grammar errors -- but no extra slack at all for laziness (and yes, we can usually spot that difference). Also, unless you know what your respondent's languages are, write in English. Busy hackers tend to simply flush questions in languages they don't understand, and English is the working language of the Internet. By writing in English you minimize your chances that your question will be discarded unread.
    Best of luck.

  • When I went to bed I had 3,000  song and multiple playlists.  This morning I have ~30 songs and no playlists.  What could have happened to my songs playlists?  I run iTunes on a Windows 7 64-bit machine.  HELP! (oh, and the Songs are not in recycle bin)

    When I went to bed I had 3,000  song and multiple playlists.  This morning I have ~30 songs and no playlists.  What could have happened to my songs playlists?  I run iTunes on a Windows 7 64-bit machine.  HELP! (oh, and the Songs are not in recycle bin)
    My wife's ipod nano was plugged into the machine overnight.
    When she went running with it, there were no songs on it.  She checked the computer and was horrified to see that the playlists had disappeared and most of the songs had disappeared.
    QUESTIONS:
    1. What could it be?
    2. How can I fix it?

    Hi, there alot of us suffering from this phernomonon but there is a forum topic about is already.
    https://discussions.apple.com/message/16767377#16767377
    Come check it out.
    Hope this works out for all of us.

  • Time machine restore help

    I've recently been having issues with my early 2008 black Macbook. I ran the apple HW diagnostics and determined it is a bad hard drive. I went out and bought a new 500GB SATA HD, and attempted to restore my system using a Time Machine backup. I booted into the Leopard Disc that came with my computer, formatted the drive, and ran the Time machine restore. Everything appeared to go fine (took about 2 hours, no error messages). However, after the machine rebooted and attempted to boot into OSX an error similar to this popped up. http://img149.imageshack.us/img149/7792/pict0017lo8.jpg
    Any thoughts as to why this is happening? I don't really want to start over with a clean install, that's why I have Time Machine!
    Other information:
    My computer originally had Leopard, and was upgraded to Snow Leopard.
    I have boot camp setup on my mac for Win 7. (I know this isn't backed up or restored as part of a time machine backup, which I'm O.K. with.)
    Thanks in advance for all your help.

    Any number of possibilities. First, did you prep the drive properly:
    Extended Hard Drive Preparation
    1. Boot from your OS X Installer Disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Installer menu (Utilities menu for Tiger, Leopard or Snow Leopard.)
    2. After DU loads select your hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Note the SMART status of the drive in DU's status area. If it does not say "Verified" then the drive is failing or has failed and will need replacing. SMART info will not be reported on external drives. Otherwise, click on the Partition tab in the DU main window.
    3. Under the Volume Scheme heading set the number of partitions from the drop down menu to one. Set the format type to Mac OS Extended (Journaled.) Click on the Options button, set the partition scheme to GUID (for Intel Macs) or APM (for PPC Macs) then click on the OK button. Click on the Partition button and wait until the process has completed.
    4. Select the volume you just created (this is the sub-entry under the drive entry) from the left side list. Click on the Erase tab in the DU main window.
    5. Set the format type to Mac OS Extended (Journaled.) Click on the Options button, check the button for Zero Data and click on OK to return to the Erase window.
    6. Click on the Erase button. The format process can take up to several hours depending upon the drive size.
    Any brand new drive should be setup per the above because they usually are configured for use on PCs rather than Macs.
    Second, depends on how you went about the process of restoring your system. Select Mac Help from the Finder's Help menu and search for "time machine." Look for an article specifically about performing a full system restore. Also, see User Tips for Time Machine for help with TM problems. Also you can select Mac Help from the Finder's Help menu and search for "time machine" to locate articles on how to use TM. See also Mac 101- Time Machine.
    What you saw was a kernel panic screen. Panics at startup may be indicative of a hardware problem. You might give this a try:
    How to run hardware diagnostics for an Intel Mac
    Boot from your original OS X Installer Disc One that came with your computer. After the chime press and hold down the "D" key until the diagnostic screen appears. Run the extended tests for a minimum of two or three hours. If any error messages appear note them down as you will need to report them to the service tech when you take the computer in for repair.
    Some "common" error indicators:
    SNS - sensor error
    MEM - memory error
    HDD - hard disk drive error
    MOT - fan error
    To assure the problem isn't with your backup you might consider installing OS X by itself. If all is OK, then you can complete the TM restore using Migration Assistant.

  • How to map and oprerate/run Vending Machine operations within SAP

    How to oprerate/run Vending Machine operations within SAP. Does SAP has this functionality to manage Vending Machine based business processes, operations and logistics.

    Have you considered using Google before posting or, perhaps, contacting your local SAP sales office?
    http://www.google.com/search?hl=en&q=SAPVendingMachines

  • HT1338 lost word document.  time machine no help.  suggestions?

    lost word document.  time machine no help. suggestions?

    Need more info. How do you think you lost a Word Document?
    Try Easy Find, Search program, and search for *.doc*. That will turn up all Word Docs with both the .DOC and .DOCX extension on your complete hard drive.
    If it is truly lost, Deleted, then you are basically SOL. Unless you do have a recent TM backup that has that file included.
    As for recovering it from TM do a search for Pondini TM FAQs.

  • Someone meet the problem, I am not abble install mac OS 10.6 snow leopard on intel based machine, (intel core 2 duo, 2,8 ghz, 4GB RAM, 320 GB HDD, OSX 10.5.8) system every time wrote "OS X snow leopard cannot be install on this machine" please help, Majo

    omeone meet the problem, I am not abble install mac OS 10.6 snow leopard on intel based machine, (intel core 2 duo, 2,8 ghz, 4GB RAM, 320 GB HDD, OSX 10.5.8) system every time wrote "OS X snow leopard cannot be install on this machine" please help, Majo

    It is retail disk, i bought it in apple store. I also resetter PRRAM and SMC and checked disk. I also tried clean installation and upgrade, nothing works, after run installation program after few seconds wrote: OS X Snow Leopard cannot be install on this machine :-(
    Thank you for your answer
    Majo

  • Vending Machine program...for loops

    I am making a vending machine program that takes an amount entered by a user, and ensures it is divisible by 5. then, it calculates the fewest number of coins to give them their change from $1. the user enters in the form of an integer, i.e. $0.25 = 25, $1 = 100. the program checks to make sure the value entered is between 25 and 100.
    I am trying to determine if this is the most efficient (fewest lines) way to calculate the number of coins...
    the variables are declared elsewhere. after this, its just System.out.print statements to output the results...
              runningCost = itemCost; // Use this variable to track the decreasing cost of the item
              for(quarters = 0; (((runningCost / QUARTER) >= 1) && (runningCost > 0)); quarters++)
                   runningCost -=QUARTER;
              for(dimes = 0; (((runningCost / DIME) >= 1) && (runningCost > 0)); dimes++)
                   runningCost -=DIME;
              for(nickels = 0; (((runningCost / NICKEL) >= 1) && (runningCost > 0)); nickels++)
                   runningCost -=NICKEL;
              }

    Cheesy goodness. Hand this one in for credit. class CoinChangeDemo {
        public enum Coin { QUARTER(25), DIME(10), NICKEL(5), PENNY(1);
            private final int value;   
            Coin(int value) { this.value = value; }
            public int value() { return value; }
        public static void main(String[] args) {
            int amount = Integer.parseInt(args[0]);
            java.util.Map<Coin, Integer> count = new java.util.HashMap<Coin, Integer>();
            for (Coin c: Coin.values()) {
                count.put(c, amount / c.value());
                amount %= c.value();
            for (Coin c : Coin.values()) {
                System.out.println(c + ": " + count.get(c));
    }Just kidding. Don't hand it in for credit, as "The Man"� may not be happy with the new featurisms.

  • I hv a macbook and hv not been able to figure out whr to enter d gateway pathway in the network settings so as to get my internet started on my machine.. help me..

    i hv a macbook and hv not been able to figure out whr to enter d gateway pathway in the network settings so as to get my internet started on my machine.. help me..

    If you go to System Preferences (under the Apple menu) and select the Network pane, then select the interface you want to use (probably Wi-Fi or AirPort if you are wireless, or Ethernet if not.) If using a static IP address you can set your router address here. If you are using DHCP, it is not needed, since the computer will pick it up automatically.
    Best of luck.

Maybe you are looking for

  • Advice appreciated on a MacBook pro HDD issue

    Hello, I've just suffered my first real system problem and even though I have a few ideas for how to fix it I thought I'd post here and ask for some advice to see what you guys think. First the problem... Basically my MacBook Pro's HDD has an issue a

  • ONLINE Backup from DB13

    Hello : When we try plan online backup and offline backup we obtein next result, BR0252E Function fopen() failed for '/oracle/CR5/sapbackup/bdxxipoo.log' at location file_printout-4 BR0253E errno 2: No such file or directory External program terminat

  • Windows installer could not be accessed?

    hey i just got a sweet new iphone, but when i went to update my itunes i keep getting this message that says "the windows installer could not be accessed. this can occur if you are running windows in safe mode or if the windows installer is not corre

  • Oracle 11g(11.1.1.6) SOA Domain creation failed

    Hi , I am new to SOA .I have downloaded s/w from OTN (ORACLE) site .I have followed the quick start guide for installation .Everything went well I have successfully installed oracle XE ,weblogic server,OEPE,RCU,OracleServiceBus. When I try to create

  • Quicktime 7.1.5

    I just upgraded to QT 7.1.5 (from QT 7.0). I had repaired permissions before and after the install, as well as, ran the disk utility which found no directory problems (from another boot partition). the problem is that the "find" command is now broken