Question: Instructions The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove
Instructions
The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly.
DebugFourteen2.java
// Displays list of payment options // - credit card, check or cash // Displays fee for using each - 5%, 2% or 0%
import javax.swing.*; import java.awt.*; import java.awt.event.*;
public class DebugFourteen2 extends JFrame implements ItemListener { FlowLayout flow = new FlowLayout(); JComboBox payMethod = new JComboBox(); JLabel payList = new JLabel("Pay List"); JTextField totFees = new JTextField(25); String pctMsg = new String("per cent will be added to your bill"); int[] fees = {5, 2, 0}; int feePct = 0; String output; int fee = 0; public DebugFourteen2() { super("Pay List) setDefaultClosetOperation(JFrame.EXIT_ON_CLOSE); setLayout(flowlayout); payMethod.addItemListener(this); add(payList); add(payMethod); payMethod.addItems("Credit card"); payMethod.addItems("Check"); payMethod.addItems("Cash"); add(totFees); } public static void main(String[] arguments) { JFrame cframe = new DebugFourteen2(); cframe.setSize(350,150); cframe.setVisible(true); } @Override public void itemStateChanged(ItemEvent list) { Object source = list.getSource(); if(source == payMethod) { int fee = payMethod.getSelectedIndex(); feePct = fees[fee]; output = feePct + " " + pctMsg; totFees.setTheText(output) } } }
----------------------------------------------------------------------------------
DebugFourteen3.java
// User selects pizza topping and sees price import javax.swing.*; import java.awt.*; import java.awt.event.*; public class DebugFourteen3 extends JFrame implements ItemListener { FlowLayout flow = new FlowLayout(); JComboBox pizzaBox = new JComboBox(); JLabel toppingList = new JLabel("Topping List); JLabel aLabel = new JLabel("Paulos's American Pie"); JTextField totPrice = new JTextField(10); int[] pizzaPrice = {7, 10, 10, 8, 8, 8, 8}; int totalPrice = 0; String output; int pizzaNum; public DebugFourteen3() { super("Pizza List"); setDefaultCloseOperation(JFrame.EXITONCLOSE); setLayout(flow); pizzaBox.addItemListener(); add(toppingList); pizzaBox.addItem("cheese"); pizzaBox.addItem("sausage"); pizzaBox.addItem("pepperoni"); pizzaBox.addItem("onion"); pizzaBox.addItem("green pepper"); pizzaBox.addItem("green olive"); pizzaBox.addItem("black olive"); add(pizzaBox); add(aLabel); add(totPrice); } public static void main(String[] arguments) { JFrame frame = new DebugFourteen3(); frame.setSizeValues(200, 150); frame.setVisible(true); }
@Override public void itemStateChanged(ItemEvent list) { Object source = list.getSource(); if(source == pizzaBox) { int pizzaNum = pizzaBox.getSelectedIndex(); total = pizzaPrice[pizzaNum]; output = "Pizza Price $" + totPrice; totPrice.setTextValue(output); } } }