You are on page 1of 19

GUI PROJECT

(BOSS CAKE)

NAME

:`NURSHAFIQA BINTI IS (2013863554)


NURUL DANIA ANIS BINTI MOHD ZAINON (2013447976)

CLASS

: CS2442B

LECTURES NAME

: DR. NORLELA BINTI SAMSUDIN

INTRODUCTION
Our project is about cake purchasing system. Our customer can
choose their choice of cakes themselves. The customer will enter their
name and phone number for customer detail. Customer can choose
whether they want the whole cake or pieces of cake. There are five
different choices of cakes which are red velvet, choc indulgence,
fruitilicious, tiramisu and blueberry cheese cake. Customer will fill in
the quantity of the cake they want. The system will calculate the bill, if
the customer is the one of Boss Cakes member, they will get 10%
discount. The system will display the receipt of the cake that customer
chose.

CLASS MENU
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
import java.text.*;

public class Menu extends JFrame


{ private JLabel image, lblSpRV, lblSpCI, lblSpF, lblSpT, lblSpBC, lblWcRV, lblWcCI, lblWcF, lblWcT,
lblWcBC;
private Container contentPane;
private JTextField lblTxt;
private JPanel pnlImage, pnlSingle, pnlWhole, pnlButton, pnlOrdr;

public static void main(String[] args)


{ Menu frame = new Menu();
frame.setVisible(true);
}

public Menu()
{ Container c = getContentPane();

pnlImage = new JPanel(new GridLayout(2,1));


pnlImage.setBorder(new TitledBorder(new EtchedBorder(), ""));
pnlImage.setPreferredSize(new Dimension(900,219));

image = new JLabel(new ImageIcon("E:\\GUI PROJECT\\BossCake.jpg"));

image.setSize(800,219);
c.add(image);

setTitle("MENU OF BOSS CAKE");


setSize(800,550);
setLocation(100,80);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

c.setLayout(new FlowLayout());
c.setLayout(new BorderLayout());

pnlSingle = new JPanel(new GridLayout(5,1));


pnlSingle.setBorder(BorderFactory.createTitledBorder("Single Portion"));

lblSpRV = new JLabel("RED VELVET

RM9.50");

lblSpCI = new JLabel("CHOC INDULGENCE

RM8.00");

lblSpF = new JLabel("FRUITILICIOUS

RM7.50");

lblSpT = new JLabel("TIRAMISU

RM7.00");

lblSpBC = new JLabel("BLUEBERRY CHEESE

RM6.50");

pnlSingle.add(lblSpRV);
pnlSingle.add(lblSpCI);
pnlSingle.add(lblSpF);
pnlSingle.add(lblSpT);
pnlSingle.add(lblSpBC);

pnlWhole = new JPanel(new GridLayout(5,1));


pnlWhole.setBorder(BorderFactory.createTitledBorder("Whole Cake"));

lblWcRV = new JLabel("RED VELVET

RM120.00");

lblWcCI = new JLabel("CHOC INDULGENCE

RM110.00");

lblWcF = new JLabel("FRUITILICIOUS

RM100.00");

lblWcT = new JLabel("TIRAMISU

RM90.00");

lblWcBC = new JLabel("BLUEBERRY CHEESE

RM80.00");

pnlWhole.add(lblWcRV);
pnlWhole.add(lblWcCI);
pnlWhole.add(lblWcF);
pnlWhole.add(lblWcT);
pnlWhole.add(lblWcBC);

pnlOrdr = new JPanel(new GridLayout(1,2));


pnlOrdr.add(pnlSingle);
pnlOrdr.add(pnlWhole);

pnlButton = new JPanel(new FlowLayout());

jButton = new javax.swing.JButton();


jButton.setText("Enter");

pnlButton.add(jButton);

c.add(pnlImage, BorderLayout.NORTH);
c.add(pnlOrdr, BorderLayout.CENTER);
c.add(pnlButton, BorderLayout.SOUTH);

jButton.addActionListener(new java.awt.event.ActionListener()
{

public void actionPerformed(java.awt.event.ActionEvent evt)


{
jButtonActionPerformed(evt);
}
});
}

private void jButtonActionPerformed(java.awt.event.ActionEvent evt)


{
setVisible(false);
new BossCake().setVisible(true);
}

private javax.swing.JButton jButton;


}

CLASS BOSS CAKE


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.util.*;
import java.text.*;

public class BossCake extends JFrame implements ActionListener


{ private JLabel title, image, lblName, lblPhoneNo, lblCake;
private JTextField txtLbl, txtName, txtPhoneNo, RVQuant, CIQuant, FQuant, TQuant, BCQuant;;
private JButton btOk, btReset, btExit, btReceipt;
private Container contentPane;
private JCheckBox[] chkMenu;
private JRadioButton[] rbMember;
private JComboBox cbCake;
private JPanel pnlServ, pnlImage, pnlInp, pnlOut, pnlButton, pnlRadio, pnlCheck, pnlQuant;
private JTextArea info;

//decimal format price


private DecimalFormat df = new DecimalFormat("0.00");

//date purchased
private Date tday = new Date();
private SimpleDateFormat dateTday = new SimpleDateFormat("ddMMyy");
private SimpleDateFormat dateTday2 = new SimpleDateFormat("dd//MM/yyyy");

//format date
private GregorianCalendar g = new GregorianCalendar();

public static void main(String[] args)


{ BossCake frame = new BossCake();
frame.setVisible(true);
}

public BossCake()
{
Container c = getContentPane();

pnlImage = new JPanel(new GridLayout(2,1));


pnlImage.setBorder(new TitledBorder(new EtchedBorder(), ""));
pnlImage.setPreferredSize(new Dimension(900,249));

image = new JLabel(new ImageIcon("E:\\GUI PROJECT\\BossCake.jpg"));


image.setSize(800,249);
c.add(image);

setTitle("BOSS CAKE");
setSize(800,500);
setLocation(100,80);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

c.setLayout(new FlowLayout());
c.setLayout(new BorderLayout());

pnlInp = new JPanel(new FlowLayout());

lblName = new JLabel("Name : ");


txtName = new JTextField(15);
txtName.setFont(new Font("Times New Roman", Font.PLAIN, 15));

lblPhoneNo = new JLabel("Phone No. : ");


txtPhoneNo = new JTextField(15);
txtPhoneNo.setFont(new Font("Times New Roman", Font.PLAIN, 15));

lblCake = new JLabel("Type cake : ");

String[] cbCakeType = {"Whole cake", "Single portion"};


cbCake = new JComboBox(cbCakeType);

pnlInp.add(lblName);
pnlInp.add(txtName);
pnlInp.add(lblPhoneNo);
pnlInp.add(txtPhoneNo);
pnlInp.add(lblCake);
pnlInp.add(cbCake);

String[] mmbBoss = {"Yes", "No"};


pnlRadio = new JPanel(new GridLayout(2,1));
pnlRadio.setBorder(BorderFactory.createTitledBorder("BOSS Member"));
ButtonGroup bg = new ButtonGroup();
rbMember = new JRadioButton[mmbBoss.length];

for(int ind = 0; ind < rbMember.length; ind++)


{ rbMember[ind] = new JRadioButton(mmbBoss[ind]);

bg.add(rbMember[ind]);
pnlRadio.add(rbMember[ind]);
}
rbMember[0].setSelected(true);

String[] chkMenuCake = {"Red Velvet", "Choc Indulgence", "Fruitilicious", "Tiramisu", "Blueberry


Cheese"};
pnlCheck = new JPanel(new GridLayout(5,1));
pnlCheck.setBorder(BorderFactory.createTitledBorder("Cake Menu"));
chkMenu = new JCheckBox[chkMenuCake.length];

for(int ind = 0; ind < chkMenu.length; ind++)


{ chkMenu[ind] = new JCheckBox(chkMenuCake[ind]);
pnlCheck.add(chkMenu[ind]);
}

pnlQuant = new JPanel(new GridLayout(5,1));


pnlQuant.setBorder(BorderFactory.createTitledBorder("Quantity Of Cake"));
pnlQuant.add(RVQuant = new JTextField(""));
pnlQuant.add(CIQuant = new JTextField(""));
pnlQuant.add(FQuant = new JTextField(""));
pnlQuant.add(TQuant = new JTextField(""));
pnlQuant.add(BCQuant = new JTextField(""));

pnlServ = new JPanel(new GridLayout(1,5));


pnlServ.setBorder(BorderFactory.createTitledBorder(""));
pnlServ.add(pnlInp);
pnlServ.add(pnlRadio);
pnlServ.add(pnlCheck);

pnlServ.add(pnlQuant);

btReset = new JButton("Reset");


btExit = new JButton("Exit");
btReceipt = new JButton("Receipt");

pnlButton = new JPanel(new FlowLayout());


pnlButton.add(btReset);
pnlButton.add(btExit);
pnlButton.add(btReceipt);

btReset.addActionListener(this);
btExit.addActionListener(this);
btReceipt.addActionListener(this);

c.add(pnlImage, BorderLayout.NORTH);
c.add(pnlServ, BorderLayout.CENTER);
c.add(pnlButton, BorderLayout.SOUTH);
}

public void actionPerformed(ActionEvent e)


{ try
{ JButton jB = (JButton) e.getSource();

double totalPrice = 0.0, totalRV = 0.0, totalCI = 0.0, totalF = 0.0, totalT = 0.0, totalBC = 0.0;

int quantRV = Integer.parseInt(RVQuant.getText());


int quantCI = Integer.parseInt(CIQuant.getText());
int quantF = Integer.parseInt(FQuant.getText());

int quantT = Integer.parseInt(TQuant.getText());


int quantBC = Integer.parseInt(BCQuant.getText());

//click button
if(jB == btReceipt)
{
String selection = (String)cbCake.getSelectedItem();

if(cbCake.getSelectedItem().equals("Whole cake"))
{ if(chkMenu[0].isSelected())
{
totalRV = quantRV * 120;
}
if(chkMenu[1].isSelected())
{
totalCI = quantCI * 110;
}
if(chkMenu[2].isSelected())
{
totalF = quantF * 100;
}
if(chkMenu[3].isSelected())
{
totalT = quantT * 90;
}
if(chkMenu[4].isSelected())
{
totalBC = quantBC * 80;
}

}
if(cbCake.getSelectedItem().equals("Single portion"))
{

if(chkMenu[0].isSelected())
{
totalRV = quantRV * 9.5;
}
if(chkMenu[1].isSelected())
{
totalCI = quantCI * 8.0;
}
if(chkMenu[2].isSelected())
{
totalF = quantF * 7.5;
}
if(chkMenu[3].isSelected())
{
totalT = quantT * 7.0;
}
if(chkMenu[4].isSelected())
{
totalBC = quantBC * 6.5;
}

totalPrice = totalRV + totalCI + totalF + totalT + totalBC;

if(rbMember[0].isSelected())
{
totalPrice = totalPrice - (0.1 * totalPrice);

}
else
{
totalPrice = totalPrice;
}

SimpleDateFormat day = new SimpleDateFormat("dd");


SimpleDateFormat month = new SimpleDateFormat("MM");
SimpleDateFormat year = new SimpleDateFormat("yyyy");

int year2 = Integer.parseInt(year.format(tday));


int month2 = Integer.parseInt(month.format(tday));
int day2 = Integer.parseInt(day.format(tday));

GregorianCalendar cal = new GregorianCalendar(year2, month2 - 1, day2);

}
if(jB == btReset)
{ txtName.setText(null);
txtPhoneNo.setText(null);

txtName.setText("");
txtPhoneNo.setText("");
RVQuant.setText("");
CIQuant.setText("");
FQuant.setText("");
TQuant.setText("");
BCQuant.setText("");

}
if(jB == btReceipt)
{
if(txtName.getText().equalsIgnoreCase(""))
{
JOptionPane.showMessageDialog(null, "Enter name");
}
else
if(txtPhoneNo.getText().equalsIgnoreCase(""))
{
JOptionPane.showMessageDialog(null, "Enter phone number");
}
else
{ JOptionPane.showMessageDialog(null,
"\nName

:" + (txtName.getText()).toUpperCase() +

"\nPhone Number

:" + (txtPhoneNo.getText()).toUpperCase() +

"\nDate Purchased

:" + dateTday2.format(tday) +

"\n\n\nBOSS CAKE :- " +


"\n(1)RED VELVET

: RM" + df.format(totalRV) +

"\n(2)CHOC INDULGENCE

: RM" + df.format(totalCI) +

"\n(3)FRUITILICIOUS

: RM" + df.format(totalF) +

"\n(4)TIRAMISU

: RM" + df.format(totalT) +

"\n(5)BLUEBERRY CHEESE : RM" + df.format(totalBC) +


"\n

--------------" +

"\nTOTAL

: RM" + df.format(totalPrice),

"CAKE RECEIPT", JOptionPane.OK_OPTION);


}
}

if(jB == btExit)
{
System.exit(0);
}
}
catch(Exception a)
{
JOptionPane.showMessageDialog(null, "Please enter the information back.");

RVQuant.setText("");
CIQuant.setText("");
FQuant.setText("");
TQuant.setText("");
BCQuant.setText("");

}
}
}

INPUT AND OUTPUT

You might also like