Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to write an applet that simulates a soft drink vending machine. The simul

ID: 3626036 • Letter: I

Question

I need to write an applet that simulates a soft drink vending machine. The simulated machine dispenses the following soft drinks: cola, lemon-lime soda, grape soda, root beer, and 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 filed 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 if 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 a drink with an inadequate amount of money entered.

everthing works but i need help when the soda of cans or water runs out of stock it need to display "drink + the drink name + out of stock" . THANKS

import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JOptionPane;
import java.awt.*;
import javax.swing.*;
import java.applet.*;
import java.awt.event.*;
public class DrinkMachine extends JApplet
{
private double balance;
private int colaClicks = 0,lemonClicks=0,grapeClicks=0,rootClicks…
private JTextField money;
private JButton cola;
private JButton lemmon;
private JButton grape;
private JButton root;
private JButton water;
private JPanel buildButtons,moneyText;

public void init()
{
setLayout(new BorderLayout());

buildButtons();

add(buildButtons, BorderLayout.EAST);

JLabel title=new JLabel("Soft Drinks .75 Each");
title.setFont(new Font("Calibri",Font.BOLD,25));
add(title,BorderLayout.WEST);

add(moneyText,BorderLayout.SOUTH);

}

private void buildButtons()
{
moneyText=new JPanel();
moneyText.setLayout(new FlowLayout());
money = new JTextField(15);
money.setPreferredSize(money.getPrefer…
money.setText("0.00");
moneyText.add(new JLabel("Enter amount tendered: "));
moneyText.add(money);

buildButtons = new JPanel();
buildButtons.setLayout(new GridLayout (5,1));
cola = new JButton("Cola");
lemmon = new JButton("Lemmon-Lime soda");
grape = new JButton("Grape Soda");
root = new JButton("Root beer");
water = new JButton("bottle water");

cola.addActionListener(new ButtonHandler());
lemmon.addActionListener(new ButtonHandler());
grape.addActionListener(new ButtonHandler());
root.addActionListener(new ButtonHandler());
water.addActionListener(new ButtonHandler());

buildButtons.add(cola);
buildButtons.add(lemmon);
buildButtons.add(grape);
buildButtons.add(root);
buildButtons.add(water);
}

private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double amount = Double.parseDouble(money.getText());

if(amount < 0.75)
JOptionPane.showMessageDialog(null, "Inadequate amount of money ");

else
{

if(e.getSource() == cola )
{
colaClicks++;
if(colaClicks <= 20)
{
balance = (amount - 0.75);
JOptionPane.showMessageDialog(null, colaClicks + " can of cola dispenced "+" "+"$"+ balance + " in change given back.");
}
else
JOptionPane.showMessageDialog(null, "Inadequate amount of money ");
}

if(e.getSource() == lemmon)
{
lemonClicks++;
if(lemonClicks <= 20)
{
balance = (amount - 0.75);
JOptionPane.showMessageDialog(null, lemonClicks + " can of lemon dispenced "+" "+"$"+ balance + " in change given back.");
}
else JOptionPane.showMessageDialog(null, "Inadequate amount of money ");
}

if(e.getSource() == grape )
{
grapeClicks++;
if(grapeClicks <= 20)
{
balance = (amount - 0.75);
JOptionPane.showMessageDialog(null, grapeClicks + " can of grape dispenced "+" "+"$"+ balance + " in change given back.");
}
else JOptionPane.showMessageDialog(null, "Inadequate amount of money ");
}

if(e.getSource() ==root )
{
rootClicks++;
if(rootClicks <= 20)
{
balance = (amount - 0.75);
JOptionPane.showMessageDialog(null, rootClicks + " can of root beer dispenced "+" "+"$"+ balance + " in change given back.");
}
else JOptionPane.showMessageDialog(null, "Inadequate amount of money ");
}


if(e.getSource() == water )
{
waterClicks++;
if(waterClicks <= 20)
{
balance = (amount - 0.75);
JOptionPane.showMessageDialog(null, waterClicks + " can of water dispenced "+" "+"$"+ balance + " in change given back.");
}
else JOptionPane.showMessageDialog(null, "Inadequate amount of money ");
}
money.setText(""+balance);

Explanation / Answer

So if sodaclicks