3 Replies - 26541 Views - Last Post: 29 March 2011 - 12:03 PM Rate Topic: -----

#1 ziggytsardust  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 3
  • Joined: 29-March 11

Pizza Java Program help!

Posted 29 March 2011 - 11:29 AM

I need help. I am making a pizza program and it gives me errors after trying to compile it.
I have 6 panels that all go together, pizzaorder is the main.

import javax.swing.*;
import java.awt.*;


/**
   The TitlePanel class displays a title in a panel.
*/

public class TitlePanel extends JPanel
{
   public TitlePanel()
	{
  		Jlabel title = new JLabel();
		title.setFont( new Font ( "Verdana", Font.BOLD, 36 ) );
		title.setText ( "Mama Mia Pizzaria" );	 
      
   	setLayout( new FlowLayout() );
		add( title );

	}
	
}


import javax.swing.*;
import java.awt.*;


public class InfoPanel extends JPanel
{
  public InfoPanel()
  {
  		setLayout( new GridLayout( 6, 2 ) );
  
 		setBorder( BorderFactory.createEmptyBorder( 5, 10, 10, 5) );
  
  		add( new JLabel( "Small:") );
  		add( new JLabel( "$4.99:") );
  
  		add( new JLabel( "$Medium:") );
  		add( new JLabel( "$6.99") );
  
  		add( new JLabel( "Large:") );
  		add( new JLabel( "$8.99:") );
  
  		add( new JLabel( "Toppings:") );
  		add( new JLabel( "$0.50 each:") );
  }
  
}
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  


import javax.swing.*;
import java.awt.*;

/**
   The SizePanel class allows the user to select coffee.
*/

public class SizePanel extends JPanel
{
   // The following constants are used to indicate
   // the cost of Pizza by size.
   public final double SMALL_SIZE = 0.0;
   public final double SIZE_MEDIUM = 1.25;
   public final double SIZE_LARGE = 1.25;
  

   private JRadioButton sizeSmall;     // To select a Small Pizza
   private JRadioButton sizeMedium; 	// To select a Medium Pizza
   private JRadioButton sizeLarge;   	// To select a Large Pizza
   private ButtonGroup bg;             // Radio button group

   /**
      Constructor
   */

   public SizePanel()
   {
      // Create a GridLayout manager with 
      // four rows and one column.
      setLayout(new GridLayout(3, 1));

      // Create the radio buttons.
      sizeSmall = new JRadioButton("Small");
      sizeMedium = new JRadioButton("Medium", true);
      sizeLarge = new JRadioButton("Large");
     

      // Group the radio buttons.
      bg = new ButtonGroup();
      bg.add(sizeSmall);
      bg.add(sizeMedium);
      bg.add(sizeLarge);
      

      // Add a border around the panel.
      setBorder(BorderFactory.createTitledBorder("Size"));

      // Add the radio buttons to the panel.
      add(sizeSmall);
      add(sizeMedium);
      add(sizeLarge);
      
   }

   /**
      getSizeCost method 
      @return The cost of the selected size.
   */

   public double getSizeCost()
   {
      double sizeCost = 0.0;

      if (sizeSmall.isSelected())
         sizeCost = SMALL_SIZE;
      else if (sizeMedium.isSelected())
         sizeCost = SIZE_MEDIUM;
      else if (sizeLarge.isSelected())
         sizeCost = SIZE_LARGE;
     

      return sizeCost;
   }
}



import javax.swing.*;
import java.awt.*;

/**
   The ToppingPanel class allows the user to select
   the toppings for the bagel.
*/

public class ToppingPanel extends JPanel
{
   // The following constants are used to indicate
   // the cost of toppings.
   public final double PEPPERONI = 0.50;
   public final double ITALIAN_SAUSAGE = 0.50;
   public final double PINEAPPLE = 0.50;
   public final double EXTRA_CHEESE = 0.50;
	public final double GREEN_PEPPER = 0.50;
	public final double OLIVES = 0.50;

   private JCheckBox pepperoni;  		// To select pepperoni
   private JCheckBox italianSausage;   // To select italianSausage
   private JCheckBox pineapple;   		// To select peach jelly
   private JCheckBox extraCheese; 		// To select blueberry jam
	

   /**
      Constructor
   */

   public ToppingPanel()
   {
      // Create a GridLayout manager with 
      // four rows and one column.
      setLayout(new GridLayout(6, 1));

      // Create the check boxes.
      pepperoni = new JCheckBox("Pepperoni");
      italianSausage = new JCheckBox("Butter");
      pineapple = new JCheckBox("Peach jelly");
      extraCheese = new JCheckBox("Blueberry jam");
		

      // Add a border around the panel.
      setBorder(BorderFactory.createTitledBorder("Toppings"));

      // Add the check boxes to the panel.
      add(pepperoni);
      add(italianSausage);
      add(pineapple);
      add(extraCheese);
		
   }

   /**
      getToppingCost method
      @return The cost of the selected toppings.
   */

   public double getToppingCost()
   {
      double toppingCost = 0.0;

      if (pepperoni.isSelected())
         toppingCost += PEPPERONI;
      if (italianSausage.isSelected())
         toppingCost += ITALIAN_SAUSAGE;
      if (pineapple.isSelected())
         toppingCost += PINEAPPLE;
      if (extraCheese.isSelected())
         toppingCost += EXTRA_CHEESE;
		

      return toppingCost;
   }
}



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;

/**
   The PizzaOrderGUI class creates the GUI for the
   Brandi's Bagel House application.
*/

public class PizzaOrderGUI extends JFrame
{
   private InfoPanel info;     // Bagel panel
   private ToppingPanel toppings; // Topping panel
   private SizePanel size;    	// SIZE panel
   private TitlePanel banner;  	// To display a greeting
   private JPanel buttonPanel;    // To hold the buttons
   private JButton calcButton;    // To calculate the cost
   private JButton exitButton;    // To exit the application
  


   /**
      Constructor
   */

   public PizzaOrderGUI()
   {
      // Display a title.
      setTitle("Order Calculator");

      // Specify an action for the close button.
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      // Create a BorderLayout manager.
      setLayout(new BorderLayout());

      // Create the custom panels.
      banner = new TitlePanel();
      info = new InfoPanel();
      toppings = new ToppingPanel();
      size = new SizePanel();

      // Create the button panel.
      buildButtonPanel();

      // Add the components to the content pane.
      add(title, BorderLayout.NORTH);
      add(info, BorderLayout.WEST);
      add(toppings, BorderLayout.CENTER);
      add(size, BorderLayout.EAST);
      add(buttonPanel, BorderLayout.SOUTH);

      // Pack the contents of the window and display it.
      pack();
      setVisible(true);
   }

   /**
      The buildButtonPanel method builds the button panel.
   */

   private void buildButtonPanel()
   {
      // Create a panel for the buttons.
      buttonPanel = new JPanel();

      // Create the buttons.
      calcButton = new JButton("Calculate");
      exitButton = new JButton("Exit");

      // Register the action listeners.
      calcButton.addActionListener(new CalcButtonListener());
      exitButton.addActionListener(new ExitButtonListener());

      // Add the buttons to the button panel.
      buttonPanel.add(calcButton);
      buttonPanel.add(exitButton);
   }

   /**
      Private inner class that handles the event when
      the user clicks the Calculate button.
   */

   private class CalcButtonListener implements ActionListener
   {
      public void actionPerformed(ActionEvent e)
      {
         // Variables to hold the subtotal, tax, and total
         double subtotal;

         // Calculate the subtotal.
         subtotal = size.getSizeCost() + 
                    toppings.getToppingCost();


         // Create a DecimalFormat object to format output.
         DecimalFormat dollar = new DecimalFormat("0.00");

         // Display the charges.
         JOptionPane.showMessageDialog(null, "Subtotal: $" +
                       dollar.format(subtotal));
      }
   }

   /**
      Private inner class that handles the event when
      the user clicks the Exit button.
   */

   private class ExitButtonListener implements ActionListener
   {
      public void actionPerformed(ActionEvent e)
      {
          System.exit(0);
      }
   }
}



*/

public class PizzaOrder
{
   public static void main(String[] args)
   {
      new PizzaOrderGUI();
   }
}



Title Panel gives me a
"TitlePanel.java:13: cannot find symbol
symbol : class Jlabel
location: class TitlePanel
Jlabel title = new JLabel();
^
1 error"

Pizza Order gives me:

"PizzaOrderGUI.java:48: title is not public in java.awt.Frame; cannot be accessed from outside package
add(title, BorderLayout.NORTH);
^
PizzaOrderGUI.java:48: cannot find symbol
symbol : method add(java.lang.String,java.lang.String)
location: class PizzaOrderGUI"

Please help!! Ive been working on this code for about 3 hours now, and I am truly frustrated.

Thank you in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Pizza Java Program help!

#2 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Pizza Java Program help!

Posted 29 March 2011 - 11:32 AM

Typo:

Jlabel title = new JLabel();
 ^



You declare a banner not a title.

You have not created a JFrame so there is no add method.

This post has been edited by n8wxs: 29 March 2011 - 11:40 AM

Was This Post Helpful? 0
  • +
  • -

#3 ziggytsardust  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 3
  • Joined: 29-March 11

Re: Pizza Java Program help!

Posted 29 March 2011 - 11:44 AM

thank you for your quick responses, i fixed the errors.

i forgot to add two extra toppings to the topping panel
and now I am receiving errors, also when i click calculate it's not giving me the correct total, can you guys please help me again!


import javax.swing.*;
import java.awt.*;


public class InfoPanel extends JPanel
{
  public InfoPanel()
  {
  		setLayout( new GridLayout( 6, 2 ) );
  
 		setBorder( BorderFactory.createEmptyBorder( 5, 10, 10, 5) );
  
  		add( new JLabel( "Small:") );
  		add( new JLabel( "$4.99:") );
  
  		add( new JLabel( "Medium:") );
  		add( new JLabel( "$6.99") );
  
  		add( new JLabel( "Large:") );
  		add( new JLabel( "$8.99:") );
  
  		add( new JLabel( "Toppings:") );
  		add( new JLabel( "$0.50 each:") );
  }
  
}
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  


import javax.swing.*;
import java.awt.*;


/**
   The TitlePanel class displays a title in a panel.
*/

public class TitlePanel extends JPanel
{
   public TitlePanel()
	{
  		JLabel title = new JLabel();
		title.setFont( new Font ( "Verdana", Font.BOLD, 36 ) );
		title.setText ( "Mama Mia Pizzaria" );	 
      
   	setLayout( new FlowLayout() );
		add( title );

	}
	
}


import javax.swing.*;
import java.awt.*;

/**
   The SizePanel class allows the user to select coffee.
*/

public class SizePanel extends JPanel
{
   // The following constants are used to indicate
   // the cost of Pizza by size.
   public final double SMALL_SIZE = 0.0;
   public final double SIZE_MEDIUM = 1.25;
   public final double SIZE_LARGE = 1.25;
  

   private JRadioButton sizeSmall;     // To select a Small Pizza
   private JRadioButton sizeMedium; 	// To select a Medium Pizza
   private JRadioButton sizeLarge;   	// To select a Large Pizza
   private ButtonGroup bg;             // Radio button group

   /**
      Constructor
   */

   public SizePanel()
   {
      // Create a GridLayout manager with 
      // four rows and one column.
      setLayout(new GridLayout(3, 1));

      // Create the radio buttons.
      sizeSmall = new JRadioButton("Small");
      sizeMedium = new JRadioButton("Medium", true);
      sizeLarge = new JRadioButton("Large");
     

      // Group the radio buttons.
      bg = new ButtonGroup();
      bg.add(sizeSmall);
      bg.add(sizeMedium);
      bg.add(sizeLarge);
      

      // Add a border around the panel.
      setBorder(BorderFactory.createTitledBorder("Size"));

      // Add the radio buttons to the panel.
      add(sizeSmall);
      add(sizeMedium);
      add(sizeLarge);
      
   }

   /**
      getSizeCost method 
      @return The cost of the selected size.
   */

   public double getSizeCost()
   {
      double sizeCost = 0.0;

      if (sizeSmall.isSelected())
         sizeCost = SMALL_SIZE;
      else if (sizeMedium.isSelected())
         sizeCost = SIZE_MEDIUM;
      else if (sizeLarge.isSelected())
         sizeCost = SIZE_LARGE;
     

      return sizeCost;
   }
}



import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;

/**
   The PizzaOrderGUI class creates the GUI for the
   Brandi's Bagel House application.
*/

public class PizzaOrderGUI extends JFrame
{
   private InfoPanel info;     // Bagel panel
   private ToppingPanel toppings; // Topping panel
   private SizePanel size;    	// SIZE panel
   private TitlePanel banner;  	// To display a greeting
   private JPanel buttonPanel;    // To hold the buttons
   private JButton calcButton;    // To calculate the cost
   private JButton exitButton;    // To exit the application
  


   /**
      Constructor
   */

   public PizzaOrderGUI()
   {
      // Display a title.
      setTitle("Order Calculator");

      // Specify an action for the close button.
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      // Create a BorderLayout manager.
      setLayout(new BorderLayout());

      // Create the custom panels.
      banner = new TitlePanel();
      info = new InfoPanel();
      toppings = new ToppingPanel();
      size = new SizePanel();

      // Create the button panel.
      buildButtonPanel();

      // Add the components to the content pane.
      add(banner, BorderLayout.NORTH);
      add(info, BorderLayout.WEST);
      add(toppings, BorderLayout.CENTER);
      add(size, BorderLayout.EAST);
      add(buttonPanel, BorderLayout.SOUTH);

      // Pack the contents of the window and display it.
      pack();
      setVisible(true);
   }

   /**
      The buildButtonPanel method builds the button panel.
   */

   private void buildButtonPanel()
   {
      // Create a panel for the buttons.
      buttonPanel = new JPanel();

      // Create the buttons.
      calcButton = new JButton("Calculate");
      exitButton = new JButton("Exit");

      // Register the action listeners.
      calcButton.addActionListener(new CalcButtonListener());
      exitButton.addActionListener(new ExitButtonListener());

      // Add the buttons to the button panel.
      buttonPanel.add(calcButton);
      buttonPanel.add(exitButton);
   }

   /**
      Private inner class that handles the event when
      the user clicks the Calculate button.
   */

   private class CalcButtonListener implements ActionListener
   {
      public void actionPerformed(ActionEvent e)
      {
         // Variables to hold the subtotal, tax, and total
         double subtotal;

         // Calculate the subtotal.
         subtotal = size.getSizeCost() + 
                    toppings.getToppingCost();


         // Create a DecimalFormat object to format output.
         DecimalFormat dollar = new DecimalFormat("0.00");

         // Display the charges.
         JOptionPane.showMessageDialog(null, "Total: $" +
                       dollar.format(subtotal));
      }
   }

   /**
      Private inner class that handles the event when
      the user clicks the Exit button.
   */

   private class ExitButtonListener implements ActionListener
   {
      public void actionPerformed(ActionEvent e)
      {
          System.exit(0);
      }
   }
}



/**
   This program creates an instance of the PizzaOrderGUI class
   which displays the GUI for the Brandi's Bagel House application.
*/

public class PizzaOrder
{
   public static void main(String[] args)
   {
      new PizzaOrderGUI();
   }
}



import javax.swing.*;
import java.awt.*;

/**
   The ToppingPanel class allows the user to select
   the toppings for the bagel.
*/

public class ToppingPanel extends JPanel
{
   // The following constants are used to indicate
   // the cost of toppings.
   public final double PEPPERONI = 0.50;
   public final double ITALIAN_SAUSAGE = 0.50;
   public final double PINEAPPLE = 0.50;
   public final double EXTRA_CHEESE = 0.50;
	public final double GREEN_PEPPER = 0.50;
	public final double OLIVES = 0.50;
	

   private JCheckBox pepperoni;  		// To select pepperoni
   private JCheckBox italianSausage;   // To select italianSausage
   private JCheckBox pineapple;   		// To select peach jelly
   private JCheckBox extraCheese; 		// To select blueberry jam
	private JCheckBox greenPepper; 		// To select blueberry jam
	private JCheckBox olives; 				// To select blueberry jam
	

   /**
      Constructor
   */

   public ToppingPanel()
   {
      // Create a GridLayout manager with 
      // four rows and one column.
      setLayout(new GridLayout(6, 1));

      // Create the check boxes.
      pepperoni = new JCheckBox("Pepperoni");
      italianSausage = new JCheckBox("Italian Sausage");
      pineapple = new JCheckBox("Pineapple");
      extraCheese = new JCheckBox("Extra Cheese");
		greenPeppers = new JCheckBox("Green Peppers");
		olives = new JCheckBox("Olives");
		

      // Add a border around the panel.
      setBorder(BorderFactory.createTitledBorder("Toppings"));

      // Add the check boxes to the panel.
      add(pepperoni);
      add(italianSausage);
      add(pineapple);
      add(extraCheese);
		add(greenPeppers);
		add(olives);
		
   }

   /**
      getToppingCost method
      @return The cost of the selected toppings.
   */

   public double getToppingCost()
   {
      double toppingCost = 0.0;

      if (pepperoni.isSelected())
         toppingCost += PEPPERONI;
      if (italianSausage.isSelected())
         toppingCost += ITALIAN_SAUSAGE;
      if (pineapple.isSelected())
         toppingCost += PINEAPPLE;
      if (extraCheese.isSelected())
         toppingCost += EXTRA_CHEESE;
		if (greenPeppers.isSelected())
         toppingCost += GREEN_PEPPER;
		if (olives.isSelected())
         toppingCost += OLIVES;
		

      return toppingCost;
   }
}



errors:

"ToppingPanel.java:44: cannot find symbol
symbol : variable greenPeppers
location: class ToppingPanel
greenPeppers = new JCheckBox("Green Peppers");
^
ToppingPanel.java:56: cannot find symbol"

thanks again in advance!
Was This Post Helpful? -1
  • +
  • -

#4 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Pizza Java Program help!

Posted 29 March 2011 - 12:03 PM

Typo:

private JCheckBox greenPepper; 
...
greenPeppers = 



Quote

"ToppingPanel.java:44: cannot find symbol
symbol : variable greenPeppers


is telling you the variable isn't declared.

This post has been edited by n8wxs: 29 March 2011 - 12:04 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1