Concept explainers
Explanation of Solution
Program:
File name: “JCarlysCaterring.java”
//Import necessary header files
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
//Define a class named JCarlysCatering
public class JCarlysCatering extends JFrame implements ItemListener, ActionListener
{
//Construct a new FlowLayout object
FlowLayout flow = new FlowLayout();
//Create a JTextField component for capturing number of //guests
JTextField guestsField = new JTextField(8);
//Create a label with the text "Please enter number of //guests"
JLabel guestsLabel = new JLabel("Please enter number of guests");
//Define CheckBoxes to capture user input for main course,
//side, items, and desert.
JCheckBox beefBox = new JCheckBox("Beef", false);
JCheckBox chickenBox = new JCheckBox("Chicken", false);
JCheckBox fishBox = new JCheckBox("Fish", false);
JCheckBox pastaBox = new JCheckBox("Pasta", false);
JCheckBox saladBox = new JCheckBox("Salad", false);
JCheckBox vegBox = new JCheckBox("Mixed vegetables", false);
JCheckBox potBox = new JCheckBox("Baked potato", false);
JCheckBox breadBox = new JCheckBox("Garlic bread", false);
JCheckBox cakeBox = new JCheckBox("Chocolate cake", false);
JCheckBox pieBox = new JCheckBox("Apple pie", false);
JCheckBox pudBox = new JCheckBox("Butterscotch pudding", false);
//Create a label with the text "Carly's Catering"
JLabel mainLabel = new JLabel("Carly's Catering");
//Set the font style of mainLabel contents
Font font = new Font("Ariel",Font.ITALIC, 30);
//Create a label with the text "Total"
JLabel label2 = new JLabel("Total");
//Create a label with the text "Select options"
JLabel label1 = new JLabel("Select options");
JLabel totPrice = new JLabel();
//Initialize the required variables
double price = 0;
String entreeString = "";
String sideString = "";
String dessertString = "";
String output;
int numSelected = 0;
//Define a default constructor
public JCarlysCatering()
{
//Set the title of the JFrame container
super("Menu options");
//Set the close and layout of the JFrame container
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(flow);
//Define a ButtonGroup object entreeGroup
ButtonGroup entreeGroup = new ButtonGroup();
//Add the check boxes for the main menu items
//to the entreeGroup
entreeGroup.add(beefBox);
entreeGroup.add(chickenBox);
entreeGroup.add(fishBox);
entreeGroup.add(pastaBox);
//Define a ButtonGroup object dessertGroup
ButtonGroup dessertGroup = new ButtonGroup();
//Add the check boxes for the dessert menu items
//to the dessertGroup
dessertGroup.add(cakeBox);
dessertGroup.add(pieBox);
dessertGroup.add(pudBox);
//Add respective components in an
//order to the container
add(mainLabel);
add(guestsLabel);
add(guestsField);
add(label1);
add(beefBox);
add(chickenBox);
add(fishBox);
add(pastaBox);
add(saladBox);
add(vegBox);
add(potBox);
add(breadBox);
add(cakeBox);
add(pieBox);
add(pudBox);
mainLabel.setFont(font);
add(label2);
add(totPrice);
totPrice.setText("$0");
//Add the item listener to the buttons
guestsField.addActionListener(this);
beefBox.addItemListener(this);
chickenBox.addItemListener(this);
fishBox.addItemListener(this);
pastaBox.addItemListener(this);
saladBox.addItemListener(this);
vegBox.addItemListener(this);
potBox.addItemListener(this);
breadBox.addItemListener(this);
cakeBox.addItemListener(this);
pieBox.addItemListener(this);
pudBox.addItemListener(this);
}
//Override method
@Override
public void actionPerformed(ActionEvent e)
{
//Get the source
Object source = e.getSource();
final int PRICE_PER_GUEST = 35;
//Check whether the text filed
if(source == guestsField)
{
//Try block
try
{
//Calculate the price
price = Integer.parseInt(guestsField.getText()) * PRICE_PER_GUEST;
}
//Catch exception
catch(Exception exc)
{
//Set the number of quests to zero
//when non-numeric value is entered
price = 0;
}
//Set the output string
output = "$" + price + " Menu includes " + entreeString +
sideString + dessertString;
totPrice...
Want to see the full answer?
Check out a sample textbook solutionChapter 14 Solutions
JAVA PROGRAM(LL)+MINDTAP (1 TERM) V2.0
- 4. def modify_data(x, my_list): X = X + 1 my_list.append(x) print(f"Inside the function: x = {x}, my_list = {my_list}") num = 5 numbers = [1, 2, 3] modify_data(num, numbers) print(f"Outside the function: num = {num}, my_list = {numbers}") Classe Classe that lin Thus, A pro is ref inter Ever dict The The output: Inside the function:? Outside the function:?arrow_forwardpython Tasks 5 • Task 1: Building a Library Management system. Write a Book class and a function to filter books by publication year. • Task 2: Create a Person class with name and age attributes, and calculate the average age of a list of people Task 3: Building a Movie Collection system. Each movie has a title, a genre, and a rating. Write a function to filter movies based on a minimum rating. ⚫ Task 4: Find Young Animals. Create an Animal class with name, species, and age attributes, and track the animals' ages to know which ones are still young. • Task 5(homework): In a store's inventory system, you want to apply discounts to products and filter those with prices above a specified amount. 27/04/1446arrow_forwardOf the five primary components of an information system (hardware, software, data, people, process), which do you think is the most important to the success of a business organization? Part A - Define each primary component of the information system. Part B - Include your perspective on why your selection is most important. Part C - Provide an example from your personal experience to support your answer.arrow_forward
- Management Information Systemsarrow_forwardQ2/find the transfer function C/R for the system shown in the figure Re དarrow_forwardPlease original work select a topic related to architectures or infrastructures (Data Lakehouse Architecture). Discussing how you would implement your chosen topic in a data warehouse project Please cite in text references and add weblinksarrow_forward
- Please original work What topic would be related to architectures or infrastructures. How you would implement your chosen topic in a data warehouse project. Please cite in text references and add weblinksarrow_forwardWhat is cloud computing and why do we use it? Give one of your friends with your answer.arrow_forwardWhat are triggers and how do you invoke them on demand? Give one reference with your answer.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage