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
MINDTAPV2.0 JAVA PROGRAMMING 2021, 1TERM
- A controller is required for a home security alarm, providing the followingfunctionality. The alarm does nothing while it is disarmed (‘switched off’). It canbe armed (‘switched on’) by entering a PIN on the keypad. Whenever thealarm is armed, it can be disarmed by entering the PIN on the keypad.If motion is detected while the alarm is armed, the siren should sound AND asingle SMS message sent to the police to notify them. Further motion shouldnot result in more messages being sent. If the siren is sounding, it can only bedisarmed by entering the PIN on the keypad. Once the alarm is disarmed, asingle SMS should be sent to the police to notify them.Two (active-high) input signals are provided to the controller:MOTION: Asserted while motion is detected inside the home.PIN: Asserted for a single clock cycle whenever the PIN has beencorrectly entered on the keypad.The controller must provide two (active-high) outputs:SIREN: The siren sounds while this output is asserted.POLICE: One SMS…arrow_forward4G+ Vo) % 1.1. LTE1 : Q B NIS شوز طبي ۱:۱۷ کا A X حاز هذا على إعجاب Mohamed Bashar. MEDICAL SHOE شوز طبي ممول . اقوى عرض بالعراق بلاش سعر القطعة ١٥ الف سعر القطعتين ٢٥ الف سعر 3 قطع ٣٥ الف القياسات : 40-41-42-43-44- افحص وكدر ثم ادفع خدمة التوصيل 5 الف لكافة محافظات العراق ופרסם BNI SH ופרסם DON JU WORLD DON JU MORISO DON JU إرسال رسالة III Messenger التواصل مع شوز طبي تعليق باسم اواب حمیدarrow_forwardA manipulator is identified by the following table of parameters and variables:a. Obtain the transformation matrices between adjacent coordinate frames and calculate the global transformation matrix.arrow_forward
- Which tool takes the 2 provided input datasets and produces the following output dataset? Input 1: Record First Last Output: 1 Enzo Cordova Record 2 Maggie Freelund Input 2: Record Frist Last MI ? First 1 Enzo Last MI Cordova [Null] 2 Maggie Freelund [Null] 3 Jason Wayans T. 4 Ruby Landry [Null] 1 Jason Wayans T. 5 Devonn Unger [Null] 2 Ruby Landry [Null] 6 Bradley Freelund [Null] 3 Devonn Unger [Null] 4 Bradley Freelund [Null] OA. Append Fields O B. Union OC. Join OD. Find Replace Clear selectionarrow_forwardWhat are the similarities and differences between massively parallel processing systems and grid computing. with referencesarrow_forwardModular Program Structure. Analysis of Structured Programming Examples. Ways to Reduce Coupling. Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsinx Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.arrow_forward
- Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsinx Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.arrow_forwardBased on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsinx Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.arrow_forwardQuestion: Based on the given problem, create an algorithm and a block diagram, and write the program code: Function: y=xsinx Interval: [0,π] Requirements: Create a graph of the function. Show the coordinates (x and y). Choose your own scale and show it in the block diagram. Create a block diagram based on the algorithm. Write the program code in Python. Requirements: Each step in the block diagram must be clearly shown. The graph of the function must be drawn and saved (in PNG format). Write the code in a modular way (functions and the main part should be separate). Please explain and describe the results in detail.arrow_forward
- 23:12 Chegg content://org.teleg + 5G 5G 80% New question A feed of 60 mol% methanol in water at 1 atm is to be separated by dislation into a liquid distilate containing 98 mol% methanol and a bottom containing 96 mol% water. Enthalpy and equilibrium data for the mixture at 1 atm are given in Table Q2 below. Ask an expert (a) Devise a procedure, using the enthalpy-concentration diagram, to determine the minimum number of equilibrium trays for the condition of total reflux and the required separation. Show individual equilibrium trays using the the lines. Comment on why the value is Independent of the food condition. Recent My stuff Mol% MeOH, Saturated vapour Table Q2 Methanol-water vapour liquid equilibrium and enthalpy data for 1 atm Enthalpy above C˚C Equilibrium dala Mol% MeOH in Saturated liquid TC kJ mol T. "Chk kot) Liquid T, "C 0.0 100.0 48.195 100.0 7.536 0.0 0.0 100.0 5.0 90.9 47,730 928 7,141 2.0 13.4 96.4 Perks 10.0 97.7 47,311 87.7 8,862 4.0 23.0 93.5 16.0 96.2 46,892 84.4…arrow_forwardYou are working with a database table that contains customer data. The table includes columns about customer location such as city, state, and country. You want to retrieve the first 3 letters of each country name. You decide to use the SUBSTR function to retrieve the first 3 letters of each country name, and use the AS command to store the result in a new column called new_country. You write the SQL query below. Add a statement to your SQL query that will retrieve the first 3 letters of each country name and store the result in a new column as new_country.arrow_forwardWe are considering the RSA encryption scheme. The involved numbers are small, so the communication is insecure. Alice's public key (n,public_key) is (247,7). A code breaker manages to factories 247 = 13 x 19 Determine Alice's secret key. To solve the problem, you need not use the extended Euclid algorithm, but you may assume that her private key is one of the following numbers 31,35,55,59,77,89.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
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning