I have no idea where to start

okay, hi! i'm trying to write a vending machine program for a class i'm taking. i have a text file with names, image URLs, and prices. I have a product class which is supposed to use filereader to read the fields in the text file. The product class is going to be loaded by the main VendMach class file, where i will have all of the main ui stuff written. The last file is the MoneyInOut class, which handles all of the money methods. i've got the majority of the UI file done, the text file is ready, and the money file is almost done...everything is hanging on whether or not i can write the product file. i have no idea where to start. any help would be greatly appreciated. i'm not looking for somebody else to write my code, but a point in the right direction would be great! here are the UI and text files:
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.text.NumberFormat;
import java.util.StringTokenizer;
// Still to be fixed:
// 1. Purchase & Maintenance buttons.
// 2. fix repaint of pictures, they don't display until a repaint is hit.
// 3. fix the Quit from program, it doesn't work right.
// 4. Put in the code for doing Maintenance.
// 5. Button super.setSize
// 6. Animate picture on selection.
public class VendMach extends Applet implements ActionListener
// Fonts for text and buttons.
private Font boldSerif16 = new Font("Serif",Font.BOLD,16);
private Font boldSerif24 = new Font("Serif",Font.BOLD,24);
private Font boldItalicSerif24 = new Font("Serif",Font.BOLD+Font.ITALIC,24);
private Font boldItalicSerif13 = new Font("Serif",Font.BOLD+Font.ITALIC,13);
private Font boldItalicSerif40 = new Font("Serif",Font.BOLD+Font.ITALIC,40);
//%% private Font boldItalicDialog16 = new Font("Dialog",Font.BOLD+Font.ITALIC,16);
// Mode flag.
private int mode = 0;
// Panels for the buttons
private Panel mainPanel = new Panel();
private Panel cashPanel = new Panel();
private Panel selPanel = new Panel();
private Panel maintPanel = new Panel();
// Product selection panel buttons
private Button selBtn[] = new Button[6];
// Cash customer puts in machine panel buttons
private Button viewC = new Button("View The Products");
private Button quit = new Button("Quit");
private Button bNickle = new Button("Nickel");
private Button bDime = new Button("Dime");
private Button bQuarter = new Button("Quarter");
private Button b$Paper = new Button("$1 Paper");
private Button b$Coin = new Button("$1 Coin");
private Label lCredit = new Label(" Credit:");
private Label lMsg = new Label("");
private Button bChange = new Button("Change Return");
private Button purchase = new Button("Purchase");
private Button maintenance = new Button("Maintenance");
private Product productForSale [];
private CashIn changeOH;
private int $collected = 0;
private double total$In = 0.00;
private NumberFormat nf;
private Image pic;
private Image picAnim;
private int prodSel = 999;
private String line;
private String f[] = new String[8];
private int tokenCount;
private int int3, int4, int5, int6, int7;
private double dbl4;
private StringTokenizer strings;
private int dispense = 99;
public void init()
{  setLayout(new BorderLayout());
productForSale = new Product[6];
try
{  BufferedReader inPut = new BufferedReader(new FileReader("Vend_Machine.txt"));
while ((line=inPut.readLine()) != null)
{  strings = new StringTokenizer(line,",");
tokenCount = strings.countTokens();
// Loop thru and retrieve each data element.
for (int i=0; i<tokenCount; i++)
f[i] = strings.nextToken();
// Load the money.
if (f[0].compareTo("M") == 0)
{  int3 = Integer.parseInt(f[3]);
int4 = Integer.parseInt(f[4]);
int5 = Integer.parseInt(f[5]);
int6 = Integer.parseInt(f[6]);
int7 = Integer.parseInt(f[7]);
changeOH = new CashIn(f[1],f[2],int3,int4,int5,int6,int7);
// Load the products.
if (f[0].compareTo("P") == 0)
{  int3 = Integer.parseInt(f[3]);
dbl4 = (new Double(f[4])).doubleValue();
int5 = Integer.parseInt(f[5]);
int6 = Integer.parseInt(f[6]);
int7 = Integer.parseInt(f[7]);
productForSale[int3] = new Product(f[1],f[2],dbl4,int5,int6,int7);
inPut.close();
catch(IOException e)
{  e.printStackTrace();
setBackground(Color.pink);
setForeground(new Color(120,0,120));
setFont(boldSerif16);
cashPanel.setLayout(new GridLayout(10,1));
cashPanel.add(viewC);
cashPanel.add(quit);
cashPanel.add(bNickle);
cashPanel.add(bDime);
cashPanel.add(bQuarter);
cashPanel.add(b$Paper);
cashPanel.add(b$Coin);
cashPanel.add(lCredit);
cashPanel.add(lMsg);
cashPanel.add(bChange);
add(cashPanel,"East");
selPanel.setLayout(new GridLayout(1,6));
for (int i=0; i<6; i++)
{  selBtn[i] = new Button(productForSale.getName());
selPanel.add(selBtn[i]);
add(selPanel,"South");
setBackground(Color.black);
viewC.addActionListener(this);
quit.addActionListener(this);
bNickle.addActionListener(this);
bDime.addActionListener(this);
bQuarter.addActionListener(this);
b$Paper.addActionListener(this);
b$Coin.addActionListener(this);
bChange.addActionListener(this);
nf = NumberFormat.getCurrencyInstance();
for (int i=0; i<6; i++)
selBtn[i].addActionListener(this);
} // =======>> END OF INIT METHOD
// ** PAINT METHOD **
public void paint(Graphics g)
{  int xVal = 35;
int yVal = 85;
int xValAnim = 0;
int yValAnim = 0;
int c = 0;
// Paint the product pictures on the vending machine.
g.setColor(Color.cyan);
g.setFont(boldItalicSerif24);
g.drawString(changeOH.getLogo1(),115,40);
g.setFont(boldItalicSerif13);
g.drawString(changeOH.getLogo2(),200,60);
for (int z=0; z<2; z++)
{  xVal = 35;
yVal = 85;
c = 0;
g.setColor(Color.black);
g.fillRect(xVal,yVal,500,350);
g.setColor(Color.yellow);
for (int i=0; i<2; i++)
{  for (int j=0; j<3; j++)
{  g.setFont(boldSerif16);
g.drawString(nf.format(productForSale[c].getPrice()),xVal+45,yVal-5);
pic = getImage(getCodeBase(),productForSale[c].getPic());
g.drawImage(pic,xVal,yVal,null);
// If product is dispensed get ready to animate.
if (c == dispense)
{  xValAnim = xVal;
yValAnim = yVal;
picAnim = pic;
xVal = xVal + 170;
c++;
yVal = yVal + 160;
xVal = 35;
// If product is dispensed, animate it.
if (dispense < 99)
{  for (int y=0; y<40; y++)
{  g.setColor(Color.black);
g.fillRect(xValAnim,yValAnim-9,125,125);
g.setColor(Color.yellow);
g.drawImage(picAnim,xValAnim,yValAnim,null);
yValAnim = yValAnim + 10;
pause(3);
dispense = 99;
if (mode == 0)
{  pic = getImage(getCodeBase(),"OutStock.gif");
g.drawImage(pic,300,300,null);
g.setColor(Color.black);
g.fillRect(1,1,500,300);
g.setColor(Color.pink);
g.setFont(boldItalicSerif40);
g.drawString(changeOH.getLogo1(),10,150);
g.setFont(boldItalicSerif24);
g.drawString(changeOH.getLogo2(),160,250);
mode++;
} // =======>> END OF PAINT METHOD
// ** ACTIONPERFORMED METHOD **
public void actionPerformed(ActionEvent event)
{  Object source = event.getSource();
lMsg.setText(" Enter up to $1.00");
// Customer puts money in the vending machine.
// Customer paid a nickle
if (source == bNickle && $collected < 96)
{  changeOH.nickleIn();
$collected = $collected + 5;
// Customer paid a dime
if (source == bDime && $collected < 91)
{  changeOH.dimeIn();
$collected = $collected + 10;
// Customer paid a quarter
if (source == bQuarter && $collected < 76)
{  changeOH.quarterIn();
$collected = $collected + 25;
// Customer paid a paper dollar
if (source == b$Paper && $collected == 0)
{  changeOH.dollarPaperIn();
$collected = $collected + 100;
// Customer paid a coin dollar
if (source == b$Coin && $collected == 0)
{  changeOH.dollarCoinIn();
$collected = $collected + 100;
// Customer makes their product selection.
for (int i=0; i<6; i++)
{  if (source == selBtn[i])
// Do nothing if customer selects item that isn't on-hand.
if (productForSale[i].getOnHand() == 0)
repaint();
// We have product on-hand.
else
{  prodSel = i;
// Tell customer to add more money if they don't have
// enough in the machine to handle the purchase.
if ($collected < (int) (productForSale[i].getPrice() * 100))
{ lMsg.setText("    Insert Money");
// Customer has enough money in machine to cover purchase.
else
{  // Take cost of item from customer's money
dbl4 = productForSale[i].getPrice() * 100;
int4 = changeOH.giveChange($collected - (int)dbl4,0);
// Tell customer to put exact amount in the machine
// because there isn't enough change to handle purchase.
if (int4 == 9)
{  lMsg.setText("Exact Amount Only!");
// **** Here the purchase was made and committed. ****
else
{  total$In = productForSale[i].getPrice() * 100;
$collected = $collected - (int) total$In;
productForSale[i].sellProduct();
dispense = i;
repaint();
// If the last product item was sold, set picture to OutStock.gif.
if (productForSale[i].getOnHand() <= 0)
productForSale[i].setOutOfStock();
if ((source == bChange || source == quit) && $collected > 0)
{  $collected = changeOH.giveChange($collected,1);
// Here we save the machine info file when customer asks
// for their change back or quits the machine.
// Customer has selected to Quit the vending machine program.
// Quit the program.
if (source == quit)
System.exit(0);
// These commands set up variables to show how much money
// the customer has in the machine.
total$In = $collected;
total$In = total$In / 100;
lCredit.setText(" Credit: " + nf.format(total$In));
repaint();
} // =======>> END OF ACTIONPERFORMED METHOD
// ** PAUSE METHOD **
public void pause(int i)
{  for(long l = System.currentTimeMillis() + (long) i; System.currentTimeMillis() < l;);
// =======>> END OF VENDMACH CLASS APPLET
// ** CASHIN CLASS **
class CashIn
{  private String logo1;
private String logo2;
private int numProd;
private int nickles;
private int dimes;
private int quarters;
private int dollarsP;
private int dollarsC;
private int money;
private double moneyVal;
private int amtToChange = 0;
private int hNickle;
private int hDime;
private int hQuarter;
private int hpDollar;
private int hcDollar;
public CashIn(String l1, String l2, int p, int q, int d, int n, int dP)
{  logo1    = l1;
logo2 = l2;
numProd = p;
quarters = q;
dimes = d;
nickles = n;
dollarsP = dP;
dollarsC = 0;
money = (n * 5) + (d * 10) + (q * 25) + (dP * 100);
// Get total of money in machine.
public double getCashIn()
{  moneyVal = money;
moneyVal = moneyVal / 100;
return moneyVal;
// Get machine record information.
public String getLogo1()
{  return logo1;
public String getLogo2()
{  return logo2;
public int getNumProd()
{  return numProd;
public int getNickles()
{  return nickles;
public int getDimes()
{  return dimes;
public int getQuarters()
{  return quarters;
public int getDollarPaper()
{  return dollarsP;
public int getDollarCoins()
{  return dollarsC;
// Money comes into the machine
public void nickleIn()
{  nickles++;
money = money + 05;
public void dimeIn()
{  dimes++;
money = money + 10;
public void quarterIn()
{  quarters++;
money = money + 25;
public void dollarPaperIn()
{  dollarsP++;
money = money + 100;
public void dollarCoinIn()
{  dollarsC++;
money = money + 100;
// Give the customer their change.
public int giveChange(int custMoney, int mode)
{  hNickle   = nickles;
hDime = dimes;
hQuarter = quarters;
hpDollar = dollarsP;
hcDollar = dollarsC;
amtToChange = custMoney / 100;
for (int i=0; i<amtToChange; i++)
{  // Give change in dollar coin if possible
if (hcDollar > 0)
{  hcDollar--;
custMoney = custMoney - 100;
// or else give change in paper dollar
else
{  if (hpDollar > 0)
{  hpDollar--;
custMoney = custMoney - 100;
amtToChange = custMoney / 25;
for (int i=0; i<amtToChange; i++)
{  if (hQuarter > 0)
{  hQuarter--;
custMoney = custMoney - 25;
amtToChange = custMoney / 10;
for (int i=0; i<amtToChange; i++)
{  if (hDime > 0)
{  hDime--;
custMoney = custMoney - 10;
amtToChange = custMoney / 5;
if (amtToChange > hNickle)
{  mode = 9;
for (int i=0; i<amtToChange; i++)
{  hNickle--;
custMoney = custMoney - 5;
if (mode == 1)
{  nickles   = hNickle;
dimes = hDime;
quarters = hQuarter;
dollarsP = hpDollar;
dollarsC = hcDollar;
money = money - custMoney;
if (mode == 9) custMoney = 9;
return custMoney;
} // =======>> END OF CASHIN CLASS
// ** PRODUCT CLASS **
class Product
{  private String name;
private String image;
private String picUsed;
private double price;
private int onHand;
private int sold;
private int maint;
public Product(String n, String i, double p, int o, int s, int m)
{  name    = n;
image = i;
picUsed = i;
price = p;
onHand = o;
sold = s;
maint = m;
// Reset picture used when product is out of stock.
public void setOutOfStock()
{  picUsed  = "OutStock.gif";
// Get product information
public String getName()
{  return name;
public String getImage()
{  return image;
public String getPic()
{  return picUsed;
public double getPrice()
{  return price;
public int getOnHand()
{  return onHand;
public int getQtySold()
{  return sold;
public int getMaintDate()
{  return maint;
// Sell one of the product.
public void sellProduct()
{  onHand--;
sold++;
// Set the product values.
public void setName(String n)
{  name = n;
public void setImage(String i)
{  image   = i;
picUsed = i;
public void setPrice(double p)
{  price = p;
public void setOnHand(int o)
{  onHand = o;
public void setQtySold(int s)
{  sold = s;
public void setMaintDate(int m)
{  maint = m; }
this is the text file
p,Fritos,Images/FritoLay.gif,
m,$.50,
p,Dr. Pepper,Images/Dr.Pepper.gif,
m,$.60,
p,Pepsi,Images/Pepsi.gif,
m,$.60,
p,Coke,Images/CocaCola.gif,
m,$.60,
p,Seven-Up,Images/7-Up.gif,
m,$.60,
p,Sprite,Images/Sprite.gif,
m,$.60,
c,10,20,40,
i know that the filereader is supposed to read the fields...i guess i just have a weak start on understanding and implementing arrays.

I write this sample some time ago, you can use it to start a new project
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CVM extends JFrame 
     JTextField mw = new JTextField("0");     
     JTextField hf = new JTextField("0");     
     JTextField ds = new JTextField("0");     
     JTextField lr = new JTextField("0");     
     JTextField py = new JTextField("0");     
     JTextField tp = new JTextField("0");     
     JTextField ch = new JTextField("0");     
public CVM()
     super("Chocolate Vending Machine");
     setBounds(0,0,500,400);
     addWindowListener(new WindowAdapter()
     {      public void windowClosing(WindowEvent ev)
               dispose();
               System.exit(0);
     JPanel pan = new JPanel();
//     pan.setLayout(new GridLayout(0,2,4,4));
     JPanel lp = new JPanel();
     lp.setBackground(Color.pink);
     lp.setLayout(new GridLayout(16,2,4,4));
     addButton(lp,"Milky Way    20$",mw);
     addButton(lp,"Hot Fudge    40$",hf);
     addButton(lp,"Dandy Shandy 50$",ds);
     addButton(lp,"Lovers Rock  80$",lr);
     addClearButton(lp);
     lp.add(new JLabel(""));
     lp.add(new JLabel(""));
     addPayButtons(lp);
     addMoneyBack(lp);
     pan.add(lp);
     setContentPane(pan);
     setVisible(true);
private void addPayButtons(JPanel pan)
     JPanel lp = new JPanel();
     lp.setOpaque(false);
     lp.setLayout(new GridLayout(0,2,4,4));
     JButton b1 = new JButton("Pay 5");
     addPay(b1,5);
     b1.setMargin(new Insets(0,0,0,0));
     JButton b2 = new JButton("Pay 10");
     addPay(b2,10);
     b2.setMargin(new Insets(0,0,0,0));
     lp.add(b1);
     lp.add(b2);
     pan.add(lp);
     lp = new JPanel();
     lp.setOpaque(false);
     lp.setBackground(Color.cyan);
     lp.setLayout(new GridLayout(0,2,4,4));
     JButton b3 = new JButton("Pay 20");
     addPay(b3,20);
     b3.setMargin(new Insets(0,0,0,0));
     JButton b4 = new JButton("Pay 50");
     addPay(b4,50);
     b4.setMargin(new Insets(0,0,0,0));
     lp.add(b3);
     lp.add(b4);
     pan.add(lp);
     pan.add(new JLabel("    Payd"));
     pan.add(py);
private void addPay(JButton bt, final int i)
     bt.addActionListener(new ActionListener()
     {     public void actionPerformed( ActionEvent e )
               int n = Integer.parseInt(py.getText())+i;
               py.setText(""+n);
               calculate();
private void addButton(JPanel pan, String s, final JTextField jt)
     JButton    bt = new JButton(s);
     bt.setHorizontalAlignment(SwingConstants.LEFT);
     bt.setMargin(new Insets(0,0,0,0));
     pan.add(bt);
     bt.addActionListener(new ActionListener()
     {     public void actionPerformed( ActionEvent e )
               int i = Integer.parseInt(jt.getText())+1;
               jt.setText(""+i);
               calculate();
     jt.setHorizontalAlignment(SwingConstants.CENTER );
     jt.setEditable(false);
     jt.setBackground(Color.white);
     pan.add(jt);
private void calculate()
     int nwi = Integer.parseInt(mw.getText()) * 20;       
     int hfi = Integer.parseInt(hf.getText()) * 40;  
     int dsi = Integer.parseInt(ds.getText()) * 50;  
     int lri = Integer.parseInt(lr.getText()) * 80;  
     int t   = nwi+hfi+dsi+lri;
     if (t >= 100) t = t - (t/10);
     tp.setText(""+t);
     int n = Integer.parseInt(py.getText());
     int c = n-t;
     ch.setText(""+c);
private void addClearButton(JPanel pan)
     pan.add(new JLabel("    To pay"));
     pan.add(tp);     
     JButton    bt = new JButton("Clear");
     bt.setHorizontalAlignment(SwingConstants.CENTER);
     bt.setMargin(new Insets(0,0,0,0));
     pan.add(bt);
     bt.addActionListener(new ActionListener()
     {     public void actionPerformed( ActionEvent e )
               mw.setText("0");       
               hf.setText("0");  
               ds.setText("0");  
               lr.setText("0");  
               tp.setText("0");  
     pan.add(new JLabel(""));
private void addMoneyBack(JPanel pan)
     JButton    bt = new JButton("Money back");
     bt.setHorizontalAlignment(SwingConstants.CENTER);
     bt.setMargin(new Insets(0,0,0,0));
     pan.add(bt);
     bt.addActionListener(new ActionListener()
     {     public void actionPerformed( ActionEvent e )
               py.setText("0");
               ch.setText("0");
     pan.add(new JLabel(""));
     pan.add(new JLabel("    Change"));
     pan.add(ch);     
public static void main( String[] args)
     new CVM();
}Noah

Similar Messages

Maybe you are looking for

  • Migrating from older macs to a new powerbook G4

    I've got one of the new powerbooks ordered and on the way, and I'm very excited about it -- improved resolution, all that screen space, tons of RAM, 1.67 mghz -- YAHOO. But I'm also dreading the moving part. Right now I've got a desktop G4 desktop im

  • Is there a way for F12 to pop up Widgets and not open apps?

    I'm a brand new Mac user with a MacBook. Before I bring up my Widgets I like to clear the screen by using the F11 button. But when I use F12 to bring up my Widgits, it also brings up any open programs behind it such as Safari. It's a little distracti

  • How to get iMovie HD

    How can I get iMovie HD?? I have iMovie 09 and 11 but I would like to get iMovie HD for the special effects.

  • Converting to imap from pop

    My mail accounts have been set up as pop accounts forever, and in downloading the mail I have set up files organizing over a decade-worth of email. These folders are in Apple Mail. In converting to imap, will this folder structure be overwritten by t

  • Shipping for service item

    can I do shipping for a service item ? what I need is : we will create service items and we need to create delivery & shipment for this service items to follow it I know I can use item category Dien ( service with delivery ) but what about shipping ?