Menu

[Solved]Java Program Break Different Classes One Program Thank Public Class Ordercalculatorguiv2 E Q37128770

Java Program. How do break this up into different classes in oneprogram? thank you

public class OrderCalculatorGUIv2 extends JFrame
{
   private JPanel bagelPanel;           // Bagel panel
   private JPanel toppingPanel;       // Topping panel
   private JPanel coffeePanel;          // Coffee panel
   private JPanel greetingPanel;        // To display a greeting
   private JPanel buttonPanel;          // To hold the buttons

   private JButton calcButton;          // To calculate thecost
   private JButton exitButton;          // To exit theapplication

   private JLabel greeting;              // For thegreetingPanel

   private JRadioButton whiteBagel;     //To select white
   private JRadioButton wheatBagel;     //To select wheat
   private ButtonGroup bagelBg;        // Radio button group

   private JRadioButton noCoffee;        // To select no coffee
   private JRadioButton regularCoffee;    // Toselect regular coffee
   private JRadioButton decafCoffee;    // To select decaf
   private JRadioButton cappuccino;      // To select cappuccino
   private ButtonGroupcoffeeBg;          // Radiobutton group

   private JCheckBox creamCheese;        // To select cream cheese
   private JCheckBoxbutter;             // To select butter
   private JCheckBox peachJelly;        // To select peach jelly
   private JCheckBox blueberryJam;       // To select blueberry jam

   private final double TAX_RATE = 0.07; // Sales taxrate

   public OrderCalculatorGUIv2()
   {

      setTitle(“Order Calculator”);

     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      setLayout(new BorderLayout());

      buildGreetingPanel();
      buildBagelPanel();
      buildToppingPanel();
      buildCoffeePanel();

      // Create the button panel.
      buildButtonPanel();

      add(greetingPanel,BorderLayout.NORTH);
      add(bagelPanel,BorderLayout.WEST);
      add(toppingPanel,BorderLayout.CENTER);
      add(coffeePanel,BorderLayout.EAST);
      add(buttonPanel,BorderLayout.SOUTH);

      pack();
      setVisible(true);
   }

   private void buildButtonPanel()
   {

      buttonPanel = new JPanel();

.
      calcButton = newJButton(“Calculate”);
      exitButton = newJButton(“Exit”);

      calcButton.addActionListener(newCalcButtonListener());
      exitButton.addActionListener(newExitButtonListener());

      buttonPanel.add(calcButton);
      buttonPanel.add(exitButton);
   }

   private void buildBagelPanel()
   {

       bagelPanel = new JPanel();

      bagelPanel.setLayout(newGridLayout(2, 1));

      whiteBagel = newJRadioButton(“White”, true);
      wheatBagel = newJRadioButton(“Wheat”);

      bagelBg = new ButtonGroup();
      bagelBg.add(whiteBagel);
      bagelBg.add(wheatBagel);

      bagelPanel.setBorder(
          BorderFactory.createTitledBorder(“Bagel”));

      bagelPanel.add(whiteBagel);
      bagelPanel.add(wheatBagel);
   }

   private void buildGreetingPanel()
   {
       // Create a panel forgreeting
       greetingPanel = new JPanel();

  
      greeting = new JLabel(“Welcome toBrandi’s Bagel House”);

      greetingPanel.add(greeting);
   }

   private void buildCoffeePanel()
   {
  
       coffeePanel = new JPanel();

      coffeePanel.setLayout(newGridLayout(4, 1));

      noCoffee = newJRadioButton(“None”);
      regularCoffee =
         newJRadioButton(“Regular coffee”, true);
      decafCoffee = newJRadioButton(“Decaf coffee”);
      cappuccino = newJRadioButton(“Cappuccino”);

      coffeeBg = new ButtonGroup();
      coffeeBg.add(noCoffee);
      coffeeBg.add(regularCoffee);
      coffeeBg.add(decafCoffee);
      coffeeBg.add(cappuccino);

   coffeePanel.setBorder(
          BorderFactory.createTitledBorder(“Coffee”));

      coffeePanel.add(noCoffee);
     coffeePanel.add(regularCoffee);
      coffeePanel.add(decafCoffee);
      coffeePanel.add(cappuccino);
   }

   private void buildToppingPanel()
   {

       toppingPanel = new JPanel();

      toppingPanel.setLayout(newGridLayout(4, 1));

      creamCheese = new JCheckBox(“Creamcheese”);
      butter = newJCheckBox(“Butter”);
      peachJelly = new JCheckBox(“Peachjelly”);
      blueberryJam = newJCheckBox(“Blueberry jam”);
      toppingPanel.setBorder(
          BorderFactory.createTitledBorder(“Toppings”));

      toppingPanel.add(creamCheese);
      toppingPanel.add(butter);
      toppingPanel.add(peachJelly);
     toppingPanel.add(blueberryJam);
   }

   private class CalcButtonListener implementsActionListener
   {
      public voidactionPerformed(ActionEvent e)
      {

         double subtotal,tax, total;

         subtotal =getBagelCost() +
                   getToppingCost() +
                   getCoffeeCost();

         tax = subtotal *TAX_RATE;

         // Calculatethe total.
         total = subtotal +tax;

         DecimalFormatdollar = new DecimalFormat(“0.00”);

        JOptionPane.showMessageDialog(null, “Subtotal: $” +
                      dollar.format(subtotal) + “n” +
                      “Tax: $” + dollar.format(tax) + “n” +
                      “Total: $” + dollar.format(total));
      }
   }

   private double getBagelCost()
   {

       final double WHITE_BAGEL =1.25;
       final double WHEAT_BAGEL =1.50;

      double bagelCost = 0.0;

      if(whiteBagel.isSelected())
         bagelCost =WHITE_BAGEL;
      else
         bagelCost =WHEAT_BAGEL;

      return bagelCost;
   }

   private double getCoffeeCost()
   {
  
       final double NO_COFFEE = 0.0;
       final double REGULAR_COFFEE =1.25;
       final double DECAF_COFFEE =1.25;
       final double CAPPUCCINO = 2.00;

      double coffeeCost = 0.0;

      if (noCoffee.isSelected())
         coffeeCost =NO_COFFEE;
      else if(regularCoffee.isSelected())
         coffeeCost =REGULAR_COFFEE;
      else if(decafCoffee.isSelected())
         coffeeCost =DECAF_COFFEE;
      else if(cappuccino.isSelected())
         coffeeCost =CAPPUCCINO;

      return coffeeCost;
   }

   private double getToppingCost()
   {

       final double CREAM_CHEESE =0.50;
       final double BUTTER = 0.25;
       final double PEACH_JELLY =0.75;
       final double BLUEBERRY_JAM =0.75;

      double toppingCost = 0.0;

      if(creamCheese.isSelected())
         toppingCost +=CREAM_CHEESE;
      if (butter.isSelected())
         toppingCost +=BUTTER;
      if (peachJelly.isSelected())
         toppingCost +=PEACH_JELLY;
      if (blueberryJam.isSelected())
         toppingCost +=BLUEBERRY_JAM;

      return toppingCost;
   }

   private class ExitButtonListener implementsActionListener
   {
      public voidactionPerformed(ActionEvent e)
      {
         System.exit(0);
      }
   }

   public static void main(String[] args)
   {
       OrderCalculatorGUIv2 gui = newOrderCalculatorGUIv2();
   }

}

Expert Answer


Answer to Java Program. How do break this up into different classes in one program? thank you public class OrderCalculatorGUIv2 ex… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *