Guest User

Untitled

a guest
Jul 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.08 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. public class BBH_GreetingPanel extends JPanel {
  4. private JLabel greeting;
  5.  
  6. public BBH_GreetingPanel() {
  7. greeting = new JLabel("Welcome to Brandi's Bagel House!");
  8.  
  9. add(greeting);
  10. }
  11. }
  12.  
  13. import javax.swing.*;
  14. import java.awt.*;
  15.  
  16. public class BBH_ToppingPanel extends JPanel {
  17. public final double CREAM_CHEESE = 0.50;
  18. public final double BUTTER = 0.25;
  19. public final double PEACH_JELLY = 0.75;
  20. public final double BLUEBERRY_JAM = 0.75;
  21.  
  22. private JCheckBox creamCheese;
  23. private JCheckBox butter;
  24. private JCheckBox peachJelly;
  25. private JCheckBox blueberryJam;
  26.  
  27. public BBH_ToppingPanel() {
  28. setLayout(new GridLayout(4, 1));
  29.  
  30. creamCheese = new JCheckBox("Cream Cheese");
  31. butter = new JCheckBox("Butter");
  32. peachJelly = new JCheckBox("Peach Jelly");
  33. blueberryJam = new JCheckBox("Blueberry Jam");
  34.  
  35. setBorder(BorderFactory.createTitledBorder("Toppings"));
  36.  
  37. add(creamCheese);
  38. add(butter);
  39. add(peachJelly);
  40. add(blueberryJam);
  41. }
  42.  
  43. public double getToppingCost() {
  44. double toppingCost = 0.0;
  45.  
  46. if(creamCheese.isSelected())
  47. toppingCost += CREAM_CHEESE;
  48. if(butter.isSelected());
  49. toppingCost += BUTTER;
  50. if(peachJelly.isSelected());
  51. toppingCost += PEACH_JELLY;
  52. if(blueberryJam.isSelected());
  53. toppingCost += BLUEBERRY_JAM;
  54.  
  55. return toppingCost;
  56. }
  57.  
  58. }
  59.  
  60. import javax.swing.*;
  61. import java.awt.*;
  62.  
  63. public class BBH_CoffeePanel extends JPanel{
  64.  
  65. public final double NO_COFFEE = 0.0;
  66. public final double REGULAR_COFFEE = 1.25;
  67. public final double DECAF_COFFEE = 1.25;
  68. public final double CAPPUCCINO = 2.00;
  69.  
  70. private JRadioButton noCoffee;
  71. private JRadioButton regularCoffee;
  72. private JRadioButton decafCoffee;
  73. private JRadioButton cappuccino;
  74. private ButtonGroup bg;
  75.  
  76. public BBH_CoffeePanel() {
  77.  
  78. setLayout(new GridLayout(4, 1));
  79.  
  80. noCoffee = new JRadioButton("None", true);
  81. regularCoffee = new JRadioButton("Regular");
  82. decafCoffee = new JRadioButton("Decaffeinated");
  83. cappuccino = new JRadioButton("Cappuccino");
  84.  
  85. bg = new ButtonGroup();
  86. bg.add(noCoffee);
  87. bg.add(regularCoffee);
  88. bg.add(decafCoffee);
  89. bg.add(cappuccino);
  90.  
  91. setBorder(BorderFactory.createTitledBorder("Coffee"));
  92.  
  93. add(noCoffee);
  94. add(regularCoffee);
  95. add(decafCoffee);
  96. add(cappuccino);
  97.  
  98. }
  99.  
  100. public double getCoffeeCost() {
  101. double coffeeCost = 0.0;
  102.  
  103. if (noCoffee.isSelected())
  104. coffeeCost = NO_COFFEE;
  105. else if (regularCoffee.isSelected())
  106. coffeeCost = REGULAR_COFFEE;
  107. else if (decafCoffee.isSelected())
  108. coffeeCost = DECAF_COFFEE;
  109. else if (cappuccino.isSelected())
  110. coffeeCost = CAPPUCCINO;
  111.  
  112.  
  113. return coffeeCost;
  114. }
  115.  
  116. }
  117.  
  118. import javax.swing.*;
  119. import java.awt.*;
  120. import java.awt.event.*;
  121.  
  122.  
  123.  
  124. public class BBH_OrderCalc extends JFrame {
  125. private BBH_BagelPanel bagels;
  126. private BBH_ToppingPanel toppings;
  127. private BBH_CoffeePanel coffee;
  128. private BBH_GreetingPanel banner;
  129. private JPanel buttonPanel;
  130. private JButton calcButton;
  131. private JButton exitButton;
  132. private final double TAX_RATE = 0.06;
  133.  
  134. public BBH_OrderCalc() {
  135.  
  136. setTitle("BBH Order Calculator");
  137.  
  138. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  139.  
  140. setLayout(new BorderLayout());
  141.  
  142. banner = new BBH_GreetingPanel();
  143. bagels = new BBH_BagelPanel();
  144. toppings = new BBH_ToppingPanel();
  145. coffee = new BBH_CoffeePanel();
  146.  
  147. buildButtonPanel();
  148.  
  149. add(banner, BorderLayout.NORTH);
  150. add(bagels, BorderLayout.WEST);
  151. add(toppings, BorderLayout.CENTER);
  152. add(coffee, BorderLayout.EAST);
  153. add(buttonPanel, BorderLayout.SOUTH);
  154.  
  155. pack();
  156. setVisible(true);
  157.  
  158.  
  159. }
  160.  
  161. private void buildButtonPanel() {
  162.  
  163. buttonPanel = new JPanel();
  164.  
  165. calcButton = new JButton("Calculate Order");
  166. exitButton = new JButton("Exit");
  167.  
  168. calcButton.addActionListener(new CalcButtonListener());
  169. exitButton.addActionListener(new ExitButtonListener()); //Error present
  170.  
  171. buttonPanel.add(calcButton);
  172. buttonPanel.add(exitButton);
  173.  
  174. }
  175.  
  176. private class CalcButtonListener implements ActionListener {
  177. public void actionPerformed(ActionEvent e) {
  178.  
  179. double subtotal, tax, total;
  180.  
  181. subtotal = bagels.getBagelCost() +
  182. toppings.getToppingCost() +
  183. coffee.getCoffeeCost();
  184.  
  185. tax = subtotal * TAX_RATE;
  186.  
  187. total = subtotal + tax;
  188.  
  189. JOptionPane.showMessageDialog(null,
  190. String.format("Subtotal: $%,.2fn" +
  191. "Tax: $%,.2fn" +
  192. "Total: $%,.2f",
  193. subtotal, tax, total));
  194.  
  195. private class ExitButtonListener implements ActionListener { //Error present
  196. public void actionPerformed(ActionEvent e) {
  197. System.exit(0);
  198. }
  199. }
  200.  
  201. }
  202. }
  203.  
  204. public static void main(String[] args) {
  205. new BBH_OrderCalc();
  206.  
  207. }
  208.  
  209. }
  210.  
  211. Exception in thread "main" java.lang.Error: Unresolved compilation problem:
  212. ExitButtonListener cannot be resolved to a type
  213.  
  214. at BBH_OrderCalc.buildButtonPanel(BBH_OrderCalc.java:50)
  215. at BBH_OrderCalc.<init>(BBH_OrderCalc.java:28)
  216. at BBH_OrderCalc.main(BBH_OrderCalc.java:86)
Add Comment
Please, Sign In to add comment