Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can you help me with this. Order total Reset button not working. It doesnt promp

ID: 3634990 • Letter: C

Question

Can you help me with this. Order total Reset button not working. It doesnt prompt total .
Thanks in advance for your help!!!

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

public class PizzaOrder extends JFrame {
double smallPizzaPrice = 7.50, mediumPizzaPrice = 12.50,largePizzaPrice = 15.50;
JLabel jlbFName, jlbLName, jlbPhoneNumber, jlbSize, jlbToppings;
JTextField jtfFName, jtfLName, jtfQuantity;
JRadioButton jrbSmall, jrbMedium, jrbLarge;
JCheckBox jcbVeggie, jcbPepproni, jcbHam, jcbCheese, jcbOlives, jcbMushrooms, jcbMeat;
JButton jbnComputeTotal, jbnReset;
JTextArea jtaOutput;



public void createInterface(){
Container c = getContentPane();
c.setLayout(new BorderLayout());


JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(3, 2));
jlbFName = new JLabel ("First Name: ");
jlbLName = new JLabel ("Last Name: ");
jlbPhoneNumber = new JLabel ("Phone Number");
jlbSize = new JLabel ("Size");



jtfFName = new JTextField();
jtfLName = new JTextField();
jtfQuantity=new JTextField();
jtfQuantity.setText("0");


p1.add(jlbFName);
p1.add(jlbLName);
p1.add(jlbPhoneNumber);
p1.add(jlbSize);
p1.add(jtfFName);
p1.add(jtfLName);
p1.add(jtfQuantity);

JPanel p2 = new JPanel();
p2.setLayout(new GridLayout(1, 3));
jrbSmall = new JRadioButton("Small", false);
jrbMedium = new JRadioButton("Medium", false);
jrbLarge = new JRadioButton("Large", false);

p2.add(jrbSmall);
p2.add(jrbMedium);
p2.add(jrbLarge);


//create logical relationship

ButtonGroup radioGroup = new ButtonGroup();
radioGroup.add(jrbSmall);
radioGroup.add(jrbMedium);
radioGroup.add(jrbLarge);

JPanel p3 = new JPanel();
p3.setLayout(new GridLayout(7, 1));
jcbVeggie = new JCheckBox("Veggie");
jcbPepproni = new JCheckBox("Pepproni");
jcbHam = new JCheckBox("Ham");
jcbCheese = new JCheckBox("Cheese");
jcbOlives = new JCheckBox("Olives");
jcbMushrooms = new JCheckBox("Mushrooms");
jcbMeat = new JCheckBox("Meat");


JPanel p4 = new JPanel();
p4.setLayout(new GridLayout(1, 2));
jbnComputeTotal = new JButton("Submit");
jbnReset = new JButton("Rest");
HButton h = new HButton();
jbnComputeTotal.addActionListener(h);
jbnReset.addActionListener(h);
jcbVeggie.addActionListener(h);
jcbPepproni.addActionListener(h);
jcbHam.addActionListener(h);
jcbCheese.addActionListener(h);
jcbOlives.addActionListener(h);
jcbMushrooms.addActionListener(h);
jcbMeat.addActionListener(h);
jrbSmall.addActionListener(h);
jrbMedium.addActionListener(h);
jrbLarge.addActionListener(h);

p4.add(jbnComputeTotal);
p4.add(jbnReset);
c.add(p2, BorderLayout.NORTH);
c.add(p3, BorderLayout.SOUTH);
c.add(p4, BorderLayout.CENTER);
c.add(p1, BorderLayout.EAST);




JPanel p5 = new JPanel();

p5.setLayout(new GridLayout(3, 1));

p5.add(p3);
p5.add(p4);

jtaOutput = new JTextArea(10, 40);
c.add(jtaOutput, BorderLayout.SOUTH);
pack();
setVisible(true);


}
public class Hbutton implements ActionListener{
public void actionPerformed (ActionEvent e){
double price = 0;
int pizzaAmount = Integer.parseInt(jtfQuantity.getText());
NumberFormat numberForm = NumberFormat.getNumberInstance();
DecimalFormat moneyForm = (DecimalFormat) numberForm;


if (jrbSmall.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jrbMedium.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jrbLarge.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbVeggie.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbPepproni.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbHam.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbCheese.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbOlives.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbMushrooms.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbMeat.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}

}
}
}



public class Pizza {


public static void main(String[] args) {

PizzaOrder pizza = new PizzaOrder();
}

}

Explanation / Answer

Dear,

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

class PizzaOrder extends JFrame {
double smallPizzaPrice = 7.50, mediumPizzaPrice = 12.50,largePizzaPrice = 15.50;
JLabel jlbFName, jlbLName, jlbPhoneNumber, jlbSize, jlbToppings;
JTextField jtfFName, jtfLName, jtfPhoneNumber,jtfQuantity;
JRadioButton jrbSmall, jrbMedium, jrbLarge;
JCheckBox jcbVeggie, jcbPepproni, jcbHam, jcbCheese, jcbOlives, jcbMushrooms, jcbMeat;
JButton jbnComputeTotal, jbnReset;
JTextArea jtaOutput;


public void createInterface(){
Container c = getContentPane();
c.setLayout(new BorderLayout());


JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(3, 2));
jlbFName = new JLabel ("First Name: ");
jtfFName = new JTextField();
jlbLName = new JLabel ("Last Name: ");
jtfLName = new JTextField();
jlbPhoneNumber = new JLabel ("Phone Number");
jtfPhoneNumber=new JTextField();
jlbSize = new JLabel ("Size");
jtfQuantity=new JTextField();
jtfQuantity.setText("0");


p1.add(jlbFName);
p1.add(jlbLName);
p1.add(jlbPhoneNumber);
p1.add(jlbSize);
p1.add(jtfFName);
p1.add(jtfLName);
p1.add(jtfQuantity);

JPanel p2 = new JPanel();
p2.setLayout(new GridLayout(1, 3));
jrbSmall = new JRadioButton("Small", false);
jrbMedium = new JRadioButton("Medium", false);
jrbLarge = new JRadioButton("Large", false);

p2.add(jrbSmall);
p2.add(jrbMedium);
p2.add(jrbLarge);


//create logical relationship

ButtonGroup radioGroup = new ButtonGroup();
radioGroup.add(jrbSmall);
radioGroup.add(jrbMedium);
radioGroup.add(jrbLarge);

JPanel p3 = new JPanel();
p3.setLayout(new GridLayout(7, 1));
jcbVeggie = new JCheckBox("Veggie");
jcbPepproni = new JCheckBox("Pepproni");
jcbHam = new JCheckBox("Ham");
jcbCheese = new JCheckBox("Cheese");
jcbOlives = new JCheckBox("Olives");
jcbMushrooms = new JCheckBox("Mushrooms");
jcbMeat = new JCheckBox("Meat");

//add labels to panel 3
p3.add(jcbVeggie );
p3.add(jcbPepproni );
p3.add(jcbHam );
p3.add(jcbCheese );
p3.add(jcbOlives );
p3.add(jcbMushrooms );
p3.add(jcbMeat );


JPanel p4 = new JPanel();
p4.setLayout(new GridLayout(1, 2));
jbnComputeTotal = new JButton("Submit");
jbnReset = new JButton("Rest");
//add buttons to panel 4
p4.add(jbnComputeTotal);
p4.add(jbnReset);

HButton h = new HButton();
jbnComputeTotal.addActionListener(h);
jbnReset.addActionListener(h);
jcbVeggie.addActionListener(h);
jcbPepproni.addActionListener(h);
jcbHam.addActionListener(h);
jcbCheese.addActionListener(h);
jcbOlives.addActionListener(h);
jcbMushrooms.addActionListener(h);
jcbMeat.addActionListener(h);
jrbSmall.addActionListener(h);
jrbMedium.addActionListener(h);
jrbLarge.addActionListener(h);

p4.add(jbnComputeTotal);
p4.add(jbnReset);
c.add(p2, BorderLayout.NORTH);
c.add(p3, BorderLayout.SOUTH);
c.add(p4, BorderLayout.CENTER);
c.add(p1, BorderLayout.EAST);

p5.setLayout(new GridLayout(3, 1));
JPanel p5 = new JPanel();

p5.add(p3);
p5.add(p4);

jtaOutput = new JTextArea(10, 40);
c.add(jtaOutput, BorderLayout.SOUTH);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);

}
public class HButton implements ActionListener{
public void actionPerformed (ActionEvent e){
double price = 0;
int pizzaAmount = Integer.parseInt(jtfQuantity.getText());
NumberFormat numberForm = NumberFormat.getNumberInstance();
DecimalFormat moneyForm = (DecimalFormat) numberForm;

if (jrbSmall.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jrbMedium.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jrbLarge.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbVeggie.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbPepproni.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbHam.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbCheese.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbOlives.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbMushrooms.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}
if (jcbMeat.isSelected()) {
price += smallPizzaPrice * pizzaAmount;
}

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

//Calling createInterface

pi.createInterface();
}

}

Hope this would helpful to you...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote