i have an important homework for my computer class...
we need to create a cash register... much like with the mcdonalds... where when the cashier would input the order... the price appears and then when the order is finished... it would sum up all the prices and would also give the amount of change...
Cash Register is a smaller version of the machines used by the cashiers in various food chains. In this
application, the user (the cashier) must be able to select the item/s ordered and indicate the quantity of each
item ordered. After each entry, the application has to be able to generate/update the receipt. When all
orders have been taken, the cashier will have to enter the amount of cash given. The application will
compute for taxes and change, and update and display the complete receipt.
here's a sample of a print screen...
http://i91.photobucket.com/albums/k2...h/jcreator.jpg
thanks.... i really need this one ASAP :)
here's my code... im stuck after this... was stucked in the addition of the prices of the ordered items... i dont know what to do next XD
Quote:
quote:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class CashRegister extends JFrame implements ActionListener
{
JLabel lblDisplay;
JLabel lblScreen;
public CashRegister ()
{
super ("Machine Project: Cash Register");
setDefaultCloseOperation (EXIT_ON_CLOSE);
setLayout (new FlowLayout ());
numpad ();
initScreen ();
setSize (1000,300);
setVisible (true);
}
public static void main (String[]args)
{ CashRegister app = new CashRegister ();
}
public void initScreen ()
{
JLabel lblTitle;
lblTitle = new JLabel ("Order: ");
add (lblTitle);
JTextField tfName;
tfName = new JTextField ();
tfName.setColumns (10);
tfName.setHorizontalAlignment(JTextField.LEFT);
add (tfName);
JButton btnEnter;
btnEnter = new JButton ("Enter");
add (btnEnter);
btnEnter.addActionListener (this);
JPanel panel = new JPanel (new BorderLayout ());
add (panel);
}
{
JLabel lblTitle;
lblTitle = new JLabel ("Quantity: ");
add (lblTitle);
JTextField tfName;
tfName = new JTextField ();
tfName.setColumns (10);
tfName.setHorizontalAlignment(JTextField.LEFT);
add (tfName);
JButton btnEnter;
btnEnter = new JButton ("Enter");
add (btnEnter);
btnEnter.addActionListener (this);
JPanel panel = new JPanel (new BorderLayout ());
add (panel);
}
{
JLabel lblTitle;
lblTitle = new JLabel ("Cash: ");
add (lblTitle);
JTextField tfName;
tfName = new JTextField ();
tfName.setHorizontalAlignment(JTextField.LEFT);
tfName.setColumns (10);
add (tfName);
JButton btnEnter;
btnEnter = new JButton ("Enter");
add (btnEnter);
btnEnter.addActionListener (this);
JPanel panel = new JPanel (new BorderLayout ());
add (panel);
{
JButton btn;
btn= new JButton ("French Fries");
btn.addActionListener (this);
panel.add (btn, BorderLayout.WEST);
btn = new JButton ("Burger");
btn.addActionListener (this);
panel.add (btn, BorderLayout.EAST);
btn = new JButton ("McFlurry");
btn.addActionListener (this);
panel.add (btn, BorderLayout.CENTER);
lblDisplay = new JLabel ();
panel.add (lblDisplay, BorderLayout.SOUTH);
}
}
public void actionPerformed (ActionEvent e)
{
JButton btn;
if (e.getActionCommand () .equals ("Enter"))
{
btn = (JButton) e.getSource ();
btn.setText ("Done");
}
else if (e.getActionCommand () .equals ("Done"))
{
btn = (JButton) e.getSource ();
btn.setText ("Enter");
}
else if (e.getActionCommand () .equals ("French Fries"))
{
lblDisplay.setText ("30");
lblDisplay.setHorizontalAlignment (JLabel.LEFT);
}
else if (e.getActionCommand () .equals ("Burger"))
{
lblDisplay.setText ("55");
lblDisplay.setHorizontalAlignment (JLabel.RIGHT);
}
else if (e.getActionCommand () .equals ("McFlurry"))
{
lblDisplay.setText ("30");
lblDisplay.setHorizontalAlignment (JLabel.CENTER);
}
}
public void numpad()
{
JTextField lblScreen;
lblScreen = new JTextField ();
lblScreen.setColumns (20);
lblScreen.setHorizontalAlignment (JTextField.RIGHT);
add (lblScreen);
}
}
|
OR THIS ONE
Quote:
quote:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class register extends JFrame implements ActionListener
{
JTextField lblScreen;
public register()
{
super ("Number Keypad Application");
setDefaultCloseOperation (EXIT_ON_CLOSE);
setLayout (new FlowLayout());
numpad ();
setSize (325,200);
setVisible (true);
}
public void numpad()
{
lblScreen= new JTextField ();
lblScreen.setColumns(12);
lblScreen.setHorizontalAlignment (JTextField.RIGHT);
add (lblScreen);
JPanel panel = new JPanel (new BorderLayout ());
add (panel);
JButton btn;
btn=new JButton ("Burger McDo");
btn.addActionListener(this);
panel.add(btn, BorderLayout.WEST);
btn=new JButton ("Cheeseburger McDo");
btn.addActionListener(this);
panel.add(btn, BorderLayout.EAST);
btn=new JButton ("Coke");
btn.addActionListener(this);
panel.add(btn, BorderLayout.CENTER);
JPanel panel2 = new JPanel (new BorderLayout ());
add (panel2);
btn=new JButton ("French Fries");
btn.addActionListener(this);
panel2.add(btn, BorderLayout.WEST);
btn=new JButton ("McDo Spaghetti");
btn.addActionListener(this);
panel2.add(btn, BorderLayout.EAST);
btn=new JButton ("McDo Sundae");
btn.addActionListener(this);
panel2.add(btn, BorderLayout.CENTER);
JPanel panel3 = new JPanel (new BorderLayout ());
add (panel3);
btn=new JButton ("McChicken");
btn.addActionListener(this);
panel3.add(btn, BorderLayout.WEST);
btn=new JButton ("McNuggets");
btn.addActionListener(this);
panel3.add(btn, BorderLayout.EAST);
btn=new JButton ("Double Cheeseburger");
btn.addActionListener(this);
panel3.add(btn, BorderLayout.CENTER);
JPanel panel4 = new JPanel (new BorderLayout ());
add (panel4);
btn=new JButton ("Quarter Pounder");
btn.addActionListener(this);
panel4.add(btn, BorderLayout.WEST);
btn=new JButton ("Restart");
btn.addActionListener(this);
panel4.add(btn, BorderLayout.EAST);
btn=new JButton ("BigMac");
btn.addActionListener(this);
panel4.add(btn, BorderLayout.CENTER);
}
public void actionPerformed (ActionEvent e)
{
JButton btn;
if (e.getActionCommand().equals("Burger McDo"))
{lblScreen.setText(lblScreen.getText()+"55");}
if (e.getActionCommand().equals("Cheeseburger McDo"))
{lblScreen.setText(lblScreen.getText()+"67");}
if (e.getActionCommand().equals("Coke"))
{lblScreen.setText(lblScreen.getText()+"20");}
if (e.getActionCommand().equals("French Fries"))
{lblScreen.setText(lblScreen.getText()+"27");}
if (e.getActionCommand().equals("McDo Spaghetti"))
{lblScreen.setText(lblScreen.getText()+"36");}
if (e.getActionCommand().equals("McDo Sundae"))
{lblScreen.setText(lblScreen.getText()+"32");}
if (e.getActionCommand().equals("McChicken"))
{lblScreen.setText(lblScreen.getText()+"70");}
if (e.getActionCommand().equals("McNuggets"))
{lblScreen.setText(lblScreen.getText()+"45");}
if (e.getActionCommand().equals("Double Cheeseburger"))
{lblScreen.setText(lblScreen.getText()+"90");}
if (e.getActionCommand().equals("Quarter Pounder"))
{lblScreen.setText(lblScreen.getText()+"108");}
if (e.getActionCommand().equals("BigMac"))
{lblScreen.setText(lblScreen.getText()+"108");}
if (e.getActionCommand().equals("Restart"))
{lblScreen.setText("");}
}
public static void main (String[]args)
{
register app= new register ();
}
}
|