oop project report

Post on 24-Apr-2015

124 Views

Category:

Education

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

 

TRANSCRIPT

oop project report

SUBMITTED TO: SIR ZAIN-UL-ABIDEEN

MINAHIL SAEED

ABDUL MATEEN

UZAIR ALI

Project Title:

Domino’s Pizza

Domino’s Pizza:Domino's Pizza is the recognized world leader in pizza delivery. Founded in 1960, Domino's is the second-largest pizza chain in the United States (after Pizza Hut) and the largest worldwide, with more than 10,000 corporate and franchised stores in 70 countries.

SUMMARY OF A PROJECT:This program will allow users to order a pizza with just a couple of clicks. The order will be a step by step by procedure. The user will be able to select from a range of Pizzas on the menu or make a Pizza of their own by choosing from different types of crusts, toppings, sidelines. When the order ends, the program will display the total cost depending on the toppings, crusts etc.

Code:

package javaapplication40;

import javax.swing.JFrame;

import javax.swing.JButton;

import javax.swing.JPanel;

import javax.swing.JLabel;

import javax.swing.ImageIcon;

import javax.swing.JCheckBox;

import javax.swing.ButtonGroup;

import javax.swing.JRadioButton;

import javax.swing.JMenu;

import javax.swing.JMenuBar;

import javax.swing.JMenuItem;

import javax.swing.JTextField;

import javax.swing.JTextArea;

import java.awt.Color;

import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;

import java.io.File;

import java.io.IOException;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.Dimension;

import java.awt.BorderLayout;

import java.awt.FlowLayout;

import javax.swing.BoxLayout;

import javax.swing.JOptionPane;

public class JavaApplication40 {

public static void main(String[] args)throws IOException {

Order obj=new Order();

}

}

class Order extends JFrame implements ActionListener

{

int total=0,sizecost=0,crustcost=0,flavorcost=0,veggiescost=0,drinkscost=0,sidescost=0;

int toppings=0,drinks=0,sides=0;

int count=0;

boolean flag=false;

String crust,flavor,size,sauce,veggies;

String text;

JPanel sizePanel=new JPanel();

JPanel crustPanel=new JPanel();

JPanel fvPanel=new JPanel();

JButton submitButton=new JButton();

JButton resetButton=new JButton();

JButton addButton=new JButton();

JTextArea totalTextArea=new JTextArea();

JMenu pepsimenu=new JMenu("Pepsi");

JMenu fantamenu=new JMenu("Fanta");

JMenu spritemenu=new JMenu("Sprite");

JMenuItem p_one=new JMenuItem("1");

JMenuItem p_two=new JMenuItem("2");

JMenuItem p_three=new JMenuItem("3");

JMenuItem p_four=new JMenuItem("4");

JMenuItem f_one=new JMenuItem("1");

JMenuItem f_two=new JMenuItem("2");

JMenuItem f_three=new JMenuItem("3");

JMenuItem f_four=new JMenuItem("4");

JMenuItem s_one=new JMenuItem("1");

JMenuItem s_two=new JMenuItem("2");

JMenuItem s_three=new JMenuItem("3");

JMenuItem s_four=new JMenuItem("4");

Order() throws IOException

{

super();

//The Main Frame

setTitle("Dominos Pakistan");

setSize(1024,786);

setLocation(0,0);

setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

getContentPane().setBackground(Color.WHITE);

FlowLayout f1=new FlowLayout();

//The Dominos Header Panel

JPanel headerPanel= new JPanel();

headerPanel.setSize(1280,200);

headerPanel.setBackground(Color.BLUE);

headerPanel.setLayout(f1);

BufferedImage headerPicture = ImageIO.read(new File("C:\\Users\\Minahil\\Documents\\Project\\header.jpg"));

JLabel headerLabel = new JLabel(new ImageIcon(headerPicture));

headerPanel.add(headerLabel);

//The Panel in which user chooses the type of Crust

crustPanel.setBackground(Color.ORANGE);

crustPanel.setLayout(new BoxLayout(crustPanel,BoxLayout.Y_AXIS));

//The 'Crust' Image used inside a Label

JLabel crustLabel=new JLabel();

ImageIcon crustImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\crust.jpg");

crustLabel.setIcon(crustImage);

crustPanel.add(crustLabel);

//The Radio Buttons used under the Crust Option

JRadioButton normalRadioButton=new JRadioButton("Normal");

normalRadioButton.addActionListener(this);

normalRadioButton.setBackground(Color.ORANGE);

JRadioButton thinzaRadioButton=new JRadioButton("Thinza");

thinzaRadioButton.addActionListener(this);

thinzaRadioButton.setBackground(Color.ORANGE);

ButtonGroup crustButtonGroup=new ButtonGroup();

crustButtonGroup.add(normalRadioButton);

crustButtonGroup.add(thinzaRadioButton);

crustPanel.add(normalRadioButton);

crustPanel.add(thinzaRadioButton);

JLabel completeLabel=new JLabel();

ImageIcon completeImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\complete.jpg");

completeLabel.setIcon(completeImage);

crustPanel.add(completeLabel);

JLabel contactLabel=new JLabel();

ImageIcon contactImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\contact.jpg");

contactLabel.setIcon(contactImage);

crustPanel.add(contactLabel);

JTextField contactTextField=new JTextField();

contactTextField.setMaximumSize(new Dimension(Integer.MAX_VALUE,contactTextField.getPreferredSize().height));

crustPanel.add(contactTextField);

JLabel nameLabel=new JLabel();

ImageIcon nameImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\name.jpg");

nameLabel.setIcon(nameImage);

crustPanel.add(nameLabel);

JTextField nameTextField=new JTextField();

nameTextField.setMaximumSize(new Dimension(Integer.MAX_VALUE,nameTextField.getPreferredSize().height));

crustPanel.add(nameTextField);

JLabel addressLabel=new JLabel();

ImageIcon addressImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\address.jpg");

addressLabel.setIcon(addressImage);

crustPanel.add(addressLabel);

JTextField addressTextField=new JTextField();

crustPanel.add(addressTextField);

//The Panel in which user selects size of the Pizza

sizePanel.setBackground(Color.ORANGE);

sizePanel.setPreferredSize(new Dimension(400,100));

sizePanel.setLayout(f1);

sizePanel.setLayout(new BoxLayout(sizePanel,BoxLayout.Y_AXIS));

//The 'Size' Image used inside a Label

JLabel sizeLabel=new JLabel();

ImageIcon sizeImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\size.jpg");

sizeLabel.setIcon(sizeImage);

sizePanel.add(sizeLabel);

//The buttons under the Size option

JRadioButton sliceRadioButton=new JRadioButton("Slice");

sliceRadioButton.addActionListener(this);

sliceRadioButton.setBackground(Color.ORANGE);

JRadioButton halfRadioButton=new JRadioButton("Half");

halfRadioButton.addActionListener(this);

halfRadioButton.setBackground(Color.ORANGE);

JRadioButton fullRadioButton=new JRadioButton("Full");

fullRadioButton.addActionListener(this);

fullRadioButton.setBackground(Color.ORANGE);

ButtonGroup sizeButtonGroup=new ButtonGroup();

sizeButtonGroup.add(sliceRadioButton);

sizeButtonGroup.add(halfRadioButton);

sizeButtonGroup.add(fullRadioButton);

sizePanel.add(sliceRadioButton);

sizePanel.add(halfRadioButton);

sizePanel.add(fullRadioButton);

JLabel sideLabel=new JLabel();

ImageIcon sideImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\side.jpg");

sideLabel.setIcon(sideImage);

sizePanel.add(sideLabel);

JCheckBox breadCheckBox=new JCheckBox("Garlic Bread");

breadCheckBox.addActionListener(this);

breadCheckBox.setBackground(Color.ORANGE);

JCheckBox wingsCheckBox=new JCheckBox("Chicken Wings");

wingsCheckBox.addActionListener(this);

wingsCheckBox.setBackground(Color.ORANGE);

JCheckBox wedgesCheckBox=new JCheckBox("Potato Wedges");

wedgesCheckBox.addActionListener(this);

wedgesCheckBox.setBackground(Color.ORANGE);

JCheckBox pocketsCheckBox=new JCheckBox("Cheesy Pockets");

pocketsCheckBox.addActionListener(this);

pocketsCheckBox.setBackground(Color.ORANGE);

sizePanel.add(breadCheckBox);

sizePanel.add(wingsCheckBox);

sizePanel.add(wedgesCheckBox);

sizePanel.add(pocketsCheckBox);

JLabel drinksLabel=new JLabel();

ImageIcon drinksImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\drinks.jpg");

drinksLabel.setIcon(drinksImage);

sizePanel.add(drinksLabel);

JMenuBar menubar=new JMenuBar();

pepsimenu.setPreferredSize(new Dimension(100, 25));

fantamenu.setPreferredSize(new Dimension(100, 25));

spritemenu.setPreferredSize(new Dimension(100, 25));

p_one.addActionListener(this);

pepsimenu.add(p_one);

p_two.addActionListener(this);

pepsimenu.add(p_two);

p_three.addActionListener(this);

pepsimenu.add(p_three);

p_four.addActionListener(this);

pepsimenu.add(p_four);

f_one.addActionListener(this);

fantamenu.add(f_one);

f_two.addActionListener(this);

fantamenu.add(f_two);

f_three.addActionListener(this);

fantamenu.add(f_three);

f_four.addActionListener(this);

fantamenu.add(f_four);

s_one.addActionListener(this);

spritemenu.add(s_one);

s_two.addActionListener(this);

spritemenu.add(s_two);

s_three.addActionListener(this);

spritemenu.add(s_three);

s_four.addActionListener(this);

spritemenu.add(s_four);

menubar.add(pepsimenu);

menubar.add(fantamenu);

menubar.add(spritemenu);

sizePanel.add(menubar);

//The panel in which user selects the type of Sauce

JPanel saucePanel=new JPanel();

saucePanel.setBackground(Color.green);

saucePanel.setLayout(f1);

//The 'Sauce' Image used inside a label

JLabel sauceLabel=new JLabel();

ImageIcon sauceImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\sauce.jpg");

sauceLabel.setIcon(sauceImage);

saucePanel.add(sauceLabel);

//The options after the Sauce label

JRadioButton mildRadioButton=new JRadioButton("Mild");

mildRadioButton.addActionListener(this);

mildRadioButton.setBackground(Color.green);

JRadioButton hotRadioButton=new JRadioButton("Hot");

hotRadioButton.addActionListener(this);

hotRadioButton.setBackground(Color.green);

JRadioButton extrahotRadioButton=new JRadioButton("Extra Hot");

extrahotRadioButton.addActionListener(this);

extrahotRadioButton.setBackground(Color.green);

ButtonGroup sauceButtonGroup=new ButtonGroup();

sauceButtonGroup.add(mildRadioButton);

sauceButtonGroup.add(hotRadioButton);

sauceButtonGroup.add(extrahotRadioButton);

saucePanel.add(mildRadioButton);

saucePanel.add(hotRadioButton);

saucePanel.add(extrahotRadioButton);

//The Add Another, Reset and Next Button

addButton.addActionListener(this);

addButton.setBackground(Color.GREEN);

ImageIcon addImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\add.jpg");

addButton.setIcon(addImage);

saucePanel.add(addButton);

resetButton.addActionListener(this);

resetButton.setBackground(Color.GREEN);

ImageIcon resetImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\reset.jpg");

resetButton.setIcon(resetImage);

saucePanel.add(resetButton);

submitButton.addActionListener(this);

submitButton.setBackground(Color.GREEN);

ImageIcon submitImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\submit.jpg");

submitButton.setIcon(submitImage);

saucePanel.add(submitButton);

//The panel in which options for flavor and vegetables is selected

fvPanel.setBackground(Color.ORANGE);

fvPanel.setPreferredSize(new Dimension(400,100));

fvPanel.setLayout(new BoxLayout(fvPanel,BoxLayout.Y_AXIS));

//The 'Flavor' image used inside a label

JLabel flavorLabel=new JLabel();

ImageIcon flavorImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\flavor.jpg");

flavorLabel.setIcon(flavorImage);

fvPanel.add(flavorLabel);

//The options displayed after Flavor

JRadioButton cheeseRadioButton=new JRadioButton("Cheese");

cheeseRadioButton.addActionListener(this);

cheeseRadioButton.setBackground(Color.ORANGE);

JRadioButton fajitaRadioButton=new JRadioButton("Chicken Fajita");

fajitaRadioButton.addActionListener(this);

fajitaRadioButton.setBackground(Color.ORANGE);

JRadioButton tikkaRadioButton=new JRadioButton("Chicken Tikka");

tikkaRadioButton.addActionListener(this);

tikkaRadioButton.setBackground(Color.ORANGE);

JRadioButton pepperoniRadioButton=new JRadioButton("Pepperoni");

pepperoniRadioButton.addActionListener(this);

pepperoniRadioButton.setBackground(Color.ORANGE);

JRadioButton vegiRadioButton=new JRadioButton("Vegitarian");

vegiRadioButton.addActionListener(this);

vegiRadioButton.setBackground(Color.ORANGE);

ButtonGroup flavorButtonGroup=new ButtonGroup();

flavorButtonGroup.add(cheeseRadioButton);

flavorButtonGroup.add(fajitaRadioButton);

flavorButtonGroup.add(tikkaRadioButton);

flavorButtonGroup.add(pepperoniRadioButton);

flavorButtonGroup.add(vegiRadioButton);

fvPanel.add(cheeseRadioButton);

fvPanel.add(fajitaRadioButton);

fvPanel.add(tikkaRadioButton);

fvPanel.add(pepperoniRadioButton);

fvPanel.add(vegiRadioButton);

//The 'Veggies' Image used inside a label

JLabel veggiesLabel=new JLabel();

ImageIcon veggiesImage=new ImageIcon("C:\\Users\\Minahil\\Documents\\Project\\veggies.jpg");

veggiesLabel.setIcon(veggiesImage);

fvPanel.add(veggiesLabel);

//The options after the Veggies image

JCheckBox olivesCheckBox=new JCheckBox("Olives");

olivesCheckBox.addActionListener(this);

olivesCheckBox.setBackground(Color.ORANGE);

JCheckBox mushroomsCheckBox=new JCheckBox("Mushroom");

mushroomsCheckBox.addActionListener(this);

mushroomsCheckBox.setBackground(Color.ORANGE);

JCheckBox capsicumCheckBox=new JCheckBox("Capsicum");

capsicumCheckBox.addActionListener(this);

capsicumCheckBox.setBackground(Color.ORANGE);

JCheckBox jalapenoesCheckBox=new JCheckBox("Jalapenoes");

jalapenoesCheckBox.addActionListener(this);

jalapenoesCheckBox.setBackground(Color.ORANGE);

fvPanel.add(olivesCheckBox);

fvPanel.add(mushroomsCheckBox);

fvPanel.add(capsicumCheckBox);

fvPanel.add(jalapenoesCheckBox);

totalTextArea.setSize(100,100);

totalTextArea.setEditable(false);

fvPanel.add(totalTextArea);

//The addition of Panels in the frame

add(saucePanel,BorderLayout.SOUTH);

add(headerPanel,BorderLayout.NORTH);

add(crustPanel,BorderLayout.CENTER);

add(sizePanel,BorderLayout.LINE_START);

add(fvPanel,BorderLayout.EAST);

setVisible(true);

}

@Override

public void actionPerformed(ActionEvent ex)

{

//switch-case statements for the selection of size of pizza

switch (ex.getActionCommand())

{

case "Slice":

{

size="Slice of a Pizza";

sizecost=250;

break;

}

case "Half":

{

size="Half a Pizza";

sizecost=800;

break;

}

case "Full":

{

size="Full Pizza";

sizecost=1500;

break;

}

}

//switch-case statements for the selection of crust of pizza

switch (ex.getActionCommand())

{

case "Normal":

{

crust="Normal Crust";

crustcost=0;

break;

}

case "Thinza":

{

crust="Thinza Crust";

crustcost=100;

break;

}

}

//switch-case statements for the selection of flavor

switch (ex.getActionCommand())

{

case "Cheese":

{

flavor="Cheese";

flavorcost=100;

break;

}

case "Chicken Fajita":

{

flavor="Chicken Fajita";

flavorcost=200;

break;

}

case "Chicken Tikka":

{

flavor="Chicken Tikka";

flavorcost=150;

break;

}

case "Pepperoni":

{

flavor="Pepperoni";

flavorcost=200;

break;

}

case "Vegitarian":

{

flavor="Vegitarian";

flavorcost=150;

break;

}

}

switch (ex.getActionCommand())

{

case "Olives":

{

toppings=toppings+1;

break;

}

case "Mushroom":

{

toppings=toppings+1;

break;

}

case "Capsicum":

{

toppings=toppings+1;

break;

}

case "Jalapenoes":

{

toppings=toppings+1;

break;

}

}

switch (ex.getActionCommand())

{

case "Mild":

{

sauce="Mild";

break;

}

case "Hot":

{

sauce="Hot";

break;

}

case "Very Hot":

{

sauce="Very Hot";

break;

}

}

switch (ex.getActionCommand())

{

case "Garlic Bread":

{

sidescost=sidescost+100;

sides=sides+1;

break;

}

case "Chicken Wings":

{

sidescost=sidescost+100;

sides=sides+1;

break;

}

case "Potato Wedges":

{

sidescost=sidescost+100;

sides=sides+1;

break;

}

case "Cheesy Pockets":

{

sidescost=sidescost+100;

sides=sides+1;

break;

}

}

if(ex.getSource()==p_one)

{

drinks=drinks+1;

drinkscost=drinkscost+60;

pepsimenu.setText("Pepsi: 1");

}

else if(ex.getSource()==p_two)

{

drinks=drinks+2;

drinkscost=drinkscost+120;

pepsimenu.setText("Pepsi: 2");

}

else if(ex.getSource()==p_three)

{

drinks=drinks+3;

drinkscost=drinkscost+180;

pepsimenu.setText("Pepsi: 3");

}

else if(ex.getSource()==p_four)

{

drinks=drinks+4;

drinkscost=drinkscost+240;

pepsimenu.setText("Pepsi: 4");

}

if(ex.getSource()==f_one)

{

drinks=drinks+1;

drinkscost=drinkscost+60;

fantamenu.setText("Fanta: 1");

}

else if(ex.getSource()==f_two)

{

drinks=drinks+2;

drinkscost=drinkscost+120;

fantamenu.setText("Fanta: 2");

}

else if(ex.getSource()==f_three)

{

drinks=drinks+3;

drinkscost=drinkscost+180;

fantamenu.setText("Fanta: 3");

}

else if(ex.getSource()==f_four)

{

drinks=drinks+4;

drinkscost=drinkscost+240;

fantamenu.setText("Fanta: 4");

}

if(ex.getSource()==s_one)

{

drinks=drinks+1;

drinkscost=drinkscost+60;

spritemenu.setText("Sprite: 1");

}

else if(ex.getSource()==s_two)

{

drinks=drinks+2;

drinkscost=drinkscost+120;

spritemenu.setText("Sprite: 2");

}

else if(ex.getSource()==s_three)

{

drinks=drinks+3;

drinkscost=drinkscost+180;

spritemenu.setText("Sprite: 3");

}

else if(ex.getSource()==s_four)

{

drinks=drinks+4;

drinkscost=drinkscost+240;

spritemenu.setText("Sprite: 4");

}

if(ex.getSource()==submitButton)

{

totalcost();

if(flag==true){

totalTextArea.setText("Your order is\n"+text+size+"\nWith "+crust+

"\nFlavor:"+flavor+"\nSauce:"+sauce+"\nWith "+toppings+

" Toppings"+"\nOrder Also includes "+sides+" Sides"+

"\nAnd "+drinks+" Drinks"+"\nThe Total is = "+total);

submitButton.setVisible(false);

}

else{

totalTextArea.setText("Your order is\n"+size+"\nWith "+crust+

"\nFlavor:"+flavor+"\nSauce:"+sauce+"\nWith "+toppings+

" Toppings"+"\nOrder Also includes "+sides+" Sides"+

"\nAnd "+drinks+" Drinks"+"\nThe Total is = "+total);

submitButton.setVisible(false);

}

}

else if(ex.getSource()==addButton){

totalcost();

JOptionPane.showMessageDialog(this,"Press Ok to add another pizza to your order","Add Another", JOptionPane.PLAIN_MESSAGE);

text = size+"\nWith "+crust+

"\nFlavor:"+flavor+"\nSauce:"+sauce+" and\n";

flag=true;

}

else if(ex.getSource()==resetButton){

total=0;

sizecost=0;

crustcost=0;

flavorcost=0;

veggiescost=0;

drinkscost=0;

sidescost=0;

toppings=0;

drinks=0;

sides=0;

crust="";

flavor="";

size="";

sauce="";

veggies="";

JOptionPane.showMessageDialog(this, "Your order has been Reset","Reset", JOptionPane.PLAIN_MESSAGE);

submitButton.setVisible(true);

}

}

public void totalcost()

{

if(toppings<=2 && toppings>0)

veggiescost=50;

else if(toppings==3)

veggiescost=150;

else if(toppings==4)

veggiescost=250;

total=total+crustcost+sizecost+flavorcost+veggiescost+drinkscost+sidescost;

} }

MAIN INTERFACE

CLASS DIAGRAM

ORDEROrder()public void actionPerformed(ActionEvent ex)public void totalcost()

int total=0, sizecost=0, crustcost=0, flavorcost=0, veggiescost=0, drinkscost=0, sidescost=0, toppings=0, drinks=0, sides=0, count=0;

boolean flag=false;

String crust,flavor,size,sauce,veggies,text;

top related