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]

[9665 byte] By [JavaProgram06a] at [2007-11-26 15:15:03]
# 1
We can't help you with BlueJ... ask whoever gave it to you. Or are you getting eror messages?
CeciNEstPasUnProgrammeura at 2007-7-8 9:06:38 > top of Java-index,Java Essentials,Java Programming...
# 2
i write it perfectly...i guess...no syntax error for 3 of them...so if i compile with jdk...how do i use it?
JavaProgram06a at 2007-7-8 9:06:38 > top of Java-index,Java Essentials,Java Programming...
# 3
javac -cp . *.javaYou'll see the syntax errors only after compiling.Which might mean if BlueJ already lights them up, it does a background compilation and your stuff already is compiled automatically. You just need to run it then.
CeciNEstPasUnProgrammeura at 2007-7-8 9:06:38 > top of Java-index,Java Essentials,Java Programming...
# 4
yeah..i manage to compile it.....how do i executed it from Bluej?
JavaProgram06a at 2007-7-8 9:06:38 > top of Java-index,Java Essentials,Java Programming...
# 5
> yeah..i manage to compile it.....how do i executed it> from Bluej?This is not a BlueJ support board. Try looking in the user help.Execution without blueJ:java -cp . YourMainClassHere
CeciNEstPasUnProgrammeura at 2007-7-8 9:06:38 > top of Java-index,Java Essentials,Java Programming...
# 6
http://pho2club.com/up/561330.jpgim having problem executing it...check the image link...am i doing wrong?
JavaProgram06a at 2007-7-8 9:06:38 > top of Java-index,Java Essentials,Java Programming...
# 7
Note the space after -cp, and no ".class":java -cp . CandyMachine
doremifasollatidoa at 2007-7-8 9:06:38 > top of Java-index,Java Essentials,Java Programming...
# 8
http://pho2club.com/up/9026ef.jpgi got this error?why?
JavaProgram06a at 2007-7-8 9:06:38 > top of Java-index,Java Essentials,Java Programming...
# 9
Because, as the stack trace say, in line 54 you do something that causes an NPE. Like using an object that doesn't exist.
CeciNEstPasUnProgrammeura at 2007-7-8 9:06:38 > top of Java-index,Java Essentials,Java Programming...
# 10

> http://pho2club.com/up/9026ef.jpg

>

> i got this error?why?

What's this rubbish I see lately where people make their error messages into images and upload them, then make us follow the link to god knows where? Don't they teach people how to copy and paste any more?

DrClapa at 2007-7-8 9:06:38 > top of Java-index,Java Essentials,Java Programming...
# 11
> Don't they teach people how to copy and paste any more?Oh come on Paul. You know they don't want to become developers really, and already earn a lot of money being soccer stars, and just do this course for charity, and the teacher explains nothing anyway. ;)
CeciNEstPasUnProgrammeura at 2007-7-8 9:06:38 > top of Java-index,Java Essentials,Java Programming...