Assignment: DrinkMachine Applet
Basic Steps in Creating your Program
1. Plan your logic before working on the project and review the syntax you will use in the project. Think about how you want the output to be displayed to the user. You might want to tell the user what the program does and what type of input you expect from the user. You interface structure could do this. Select names of the variables you will use in the program.
2. Create a JAVA project Using NetBeans IDE. And have the code window open to write the project code. Here are some instructions on creating the project.
• Declare variables to hold input information.
• Using the JOptionPane Concept. (Some programs might need just the Scanner.
• Ask the user to enter some information requested and save the response to a variable. This could look like: name = JOptionPane.showInputDialog ("Enter your name").
• Use line spacing (i.e.\n) to separate lines of output to make it easy for the user to read the information and have proper line length.
3. Documentation: All lines of code must be documented.
• Use the syntax to designate lines in code as comments (//)
• These comments can be at the end of a line of code or in a group definition at the beginning of a section of code. All methods and function need a group heading document.
4. Run the program using Run Project menu item.Debug the code, making sure all calculations are correct and the line spacing is suitable for readability.
Your program Assignment
Write an applet that simulates a soft drink vending machine. The simulated machine dispenses the following soft drink:
• Cola
• Lemon-lime
• Grape
• soda,
• root beer
• bottled water
These drinks cost #0.75 each to purchase.
When the applet starts, the drink machine should have a supply of 20 of each of the drinks. The applet should have a text field where the user can enter the amount of money he or she is giving the machine. The user can then click on a button to select a drink to dispense. The applet should also display the amount of change it is giving back to the user. The applet should keep track of its inventory of drinks and inform the user whether he or she has selected a drink that is out of stock. Be sure to handle operator errors such as selecting a drink with no money entered and selecting.