java code does not run and I don't know what is wrong with it. can someone help fix it. import javax.swing.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class RestaurantOrderSystem extends JFrame implements ActionListener {          private JLabel title;     private JPanel panel;     private JComboBox foodList;     private JCheckBox extraCheese;     private JRadioButton smallSize, mediumSize, largeSize;     private JTextField totalPrice;     private JButton orderButton;          private double basePrice = 0.0;     private double total = 0.0;          public RestaurantOrderSystem() {         setTitle("Restaurant Order System");         setSize(400, 400);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);                  // create title label         title = new JLabel("Select your food and options:");         title.setBounds(20, 10, 300, 30);         add(title);                  // create panel for components         panel = new JPanel();         panel.setLayout(null);         panel.setBounds(20, 50, 300, 140);         add(panel);                  // create food list combo box         String[] foodOptions = {"Pizza", "Burger", "Fries", "Salad"};         foodList = new JComboBox<>(foodOptions);         foodList.setBounds(10, 10, 120, 30);         panel.add(foodList);                  // create extra cheese check box         extraCheese = new JCheckBox("Extra Cheese (+$1.50)");         extraCheese.setBounds(10, 50, 200, 30);         panel.add(extraCheese);                  // create pizza size radio buttons         smallSize = new JRadioButton("Small ($5.00)");         smallSize.setBounds(10, 90, 100, 30);         smallSize.addActionListener(this);         panel.add(smallSize);                  mediumSize = new JRadioButton("Medium ($7.50)");         mediumSize.setBounds(110, 90, 120, 30);         mediumSize.addActionListener(this);         panel.add(mediumSize);                  largeSize = new JRadioButton("Large ($10.00)");         largeSize.setBounds(230, 90, 100, 30);         largeSize.addActionListener(this);         panel.add(largeSize);                  // create total price text field         totalPrice = new JTextField("$0.00");         totalPrice.setBounds(140, 10, 150, 30);         totalPrice.setEditable(false);         panel.add(totalPrice);                  // create order button         orderButton = new JButton("Place Order");         orderButton.setBounds(110, 190, 120, 30);         orderButton.addActionListener(this);         add(orderButton);                  setVisible(true);     }          public void actionPerformed(ActionEvent e) {         if (e.getSource() == smallSize) {             basePrice = 5.0;             updateTotalPrice();         } else if (e.getSource() == mediumSize) {             basePrice = 7.5;             updateTotalPrice();         } else if (e.getSource() == largeSize) {             basePrice = 10.0;             updateTotalPrice();         } else if (e.getSource() == orderButton) {             JOptionPane.showMessageDialog(this, "Your order has been placed. Total cost: " + totalPrice.getText());         }     }          private void updateTotalPrice() {         total = basePrice;         if (extraCheese.isSelected()) {             total += 1.5;         }         totalPrice.setText("$" + String.format("%.2f", total));     }          public static void main(String[] args) {         RestaurantOrderSystem ros = new RestaurantOrderSystem();     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 java code does not run and I don't know what is wrong with it. can someone help fix it.

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class RestaurantOrderSystem extends JFrame implements ActionListener {
    
    private JLabel title;
    private JPanel panel;
    private JComboBox<String> foodList;
    private JCheckBox extraCheese;
    private JRadioButton smallSize, mediumSize, largeSize;
    private JTextField totalPrice;
    private JButton orderButton;
    
    private double basePrice = 0.0;
    private double total = 0.0;
    
    public RestaurantOrderSystem() {
        setTitle("Restaurant Order System");
        setSize(400, 400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        
        // create title label
        title = new JLabel("Select your food and options:");
        title.setBounds(20, 10, 300, 30);
        add(title);
        
        // create panel for components
        panel = new JPanel();
        panel.setLayout(null);
        panel.setBounds(20, 50, 300, 140);
        add(panel);
        
        // create food list combo box
        String[] foodOptions = {"Pizza", "Burger", "Fries", "Salad"};
        foodList = new JComboBox<>(foodOptions);
        foodList.setBounds(10, 10, 120, 30);
        panel.add(foodList);
        
        // create extra cheese check box
        extraCheese = new JCheckBox("Extra Cheese (+$1.50)");
        extraCheese.setBounds(10, 50, 200, 30);
        panel.add(extraCheese);
        
        // create pizza size radio buttons
        smallSize = new JRadioButton("Small ($5.00)");
        smallSize.setBounds(10, 90, 100, 30);
        smallSize.addActionListener(this);
        panel.add(smallSize);
        
        mediumSize = new JRadioButton("Medium ($7.50)");
        mediumSize.setBounds(110, 90, 120, 30);
        mediumSize.addActionListener(this);
        panel.add(mediumSize);
        
        largeSize = new JRadioButton("Large ($10.00)");
        largeSize.setBounds(230, 90, 100, 30);
        largeSize.addActionListener(this);
        panel.add(largeSize);
        
        // create total price text field
        totalPrice = new JTextField("$0.00");
        totalPrice.setBounds(140, 10, 150, 30);
        totalPrice.setEditable(false);
        panel.add(totalPrice);
        
        // create order button
        orderButton = new JButton("Place Order");
        orderButton.setBounds(110, 190, 120, 30);
        orderButton.addActionListener(this);
        add(orderButton);
        
        setVisible(true);
    }
    
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == smallSize) {
            basePrice = 5.0;
            updateTotalPrice();
        } else if (e.getSource() == mediumSize) {
            basePrice = 7.5;
            updateTotalPrice();
        } else if (e.getSource() == largeSize) {
            basePrice = 10.0;
            updateTotalPrice();
        } else if (e.getSource() == orderButton) {
            JOptionPane.showMessageDialog(this, "Your order has been placed. Total cost: " + totalPrice.getText());
        }
    }
    
    private void updateTotalPrice() {
        total = basePrice;
        if (extraCheese.isSelected()) {
            total += 1.5;
        }
        totalPrice.setText("$" + String.format("%.2f", total));
    }
    
    public static void main(String[] args) {
        RestaurantOrderSystem ros = new RestaurantOrderSystem();
    }
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 6 images

Blurred answer
Knowledge Booster
JQuery and Javascript
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education