How to compile this program.....
i just started on second semester and my advisor gave me a script to write...but i dont know how to compile this program...im using a BlueJ compiler
this is the source code
File 1 CashRegister.java
publicclass CashRegister
{
privateint cashOnHand;
public CashRegister()
{
cashOnHand=500;
}
public CashRegister (int cashIn)
{
if (cashIn >=0)
cashOnHand= cashIn;
else
cashOnHand=500;
}
publicint currentBalance()
{
return cashOnHand;
}
publicvoid acceptAmount(int amountIn)
{
}
}
File 2 Dispenser.java
publicclass Dispenser
{
privateint numberOfItems;
privateint cost;
public Dispenser()
{
numberOfItems=50;
cost=50;
}
public Dispenser (int setNoOfItems,int setCost)
{
if (setNoOfItems>=0)
numberOfItems=setNoOfItems;
else
numberOfItems=50;
if (setCost>=0)
cost=setCost;
else
cost=50;
}
publicint getCount()
{
return numberOfItems;
}
publicint getProductCost()
{
return cost;
}
publicvoid makeSale()
{
numberOfItems--;
}
}
File 3 CandyMachine.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
publicclass CandyMachineextends JFrame
{
privatestaticfinalint WIDTH=300;
privatestaticfinalint HEIGHT=300;
private CashRegister cashRegister=new CashRegister();
private Dispenser candy=new Dispenser (100,50);
private Dispenser chips=new Dispenser (100,65);
private Dispenser gum=new Dispenser (75,45);
private Dispenser cookies=new Dispenser (100,85);
private JLabel headingMainL;
private JLabel selectionL;
private JButton exitB, candyB, chipsB, gumB, cookiesB;
private ButtonHandler pbHandler;
public CandyMachine()
{
setTitle ("Candy Machine");
setSize (WIDTH,HEIGHT);
Container pane=getContentPane();
pane.setLayout(new GridLayout (7,1));
pbHandler=new ButtonHandler();
headingMainL=new JLabel ("WELCOME TO HASSAN'S CANDY SHOP",SwingConstants.CENTER);
selectionL=new JLabel ("To Make a Selection, "+"Click on the Product Button", SwingConstants.CENTER);
pane.add (headingMainL);
pane.add (selectionL);
candyB=new JButton ("Candy");
candyB.addActionListener (pbHandler);
chipsB=new JButton ("Chips");
chipsB.addActionListener (pbHandler);
gumB=new JButton ("Gum");
gumB.addActionListener (pbHandler);
exitB=new JButton ("Exit");
exitB.addActionListener (pbHandler);
pane.add(candyB);
pane.add(chipsB);
pane.add(gumB);
pane.add(cookiesB);
pane.add(exitB);
setVisible (true);
setDefaultCloseOperation (EXIT_ON_CLOSE);
}
privateclass ButtonHandlerimplements ActionListener
{
publicvoid actionPerformed (ActionEvent e)
{
if (e.getActionCommand().equals ("Exit"))
System.exit(0);
elseif (e.getActionCommand().equals("Candy"))
sellProduct (candy,"Candy");
elseif (e.getActionCommand().equals("Chips"))
sellProduct (chips,"Chips");
elseif (e.getActionCommand().equals("Gum"))
sellProduct (gum,"Gum");
elseif (e.getActionCommand().equals("Cookies"))
sellProduct (cookies,"Cookies");
}
}
privatevoid sellProduct (Dispenser product, String productName)
{
int coinsInserted=0;
int price, coinsRequired;
String str;
if (product.getCount() >0)
{
price=product.getProductCost();
coinsRequired=price-coinsInserted;
while(coinsRequired>0)
{
str=JOptionPane.showInputDialog("To buy"+productName+" please insert "+coinsRequired+" cents ");
coinsInserted=coinsInserted+ Integer.parseInt(str);
coinsRequired=price-coinsInserted;
}
cashRegister.acceptAmount (coinsInserted);
product.makeSale();
JOptionPane.showMessageDialog (null,"Please pick up your "+productName+" and enjoy","Thank you. Come again!",JOptionPane.PLAIN_MESSAGE);
}
else
JOptionPane.showMessageDialog(null,"Sorry"+productName+"is sold out \n"+"Make another selection","Thank you. Come again!",JOptionPane.PLAIN_MESSAGE);
}
publicstaticvoid main (String [] args)
{
CandyMachine candyShop=new CandyMachine();
}
}
this is the compiler...
[img]http://pho2club.com/up/38e75b.jpg[/img]

