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
EBK JAVA PROGRAMMING
- GUI calculator in python - The user enters two integers into the text fields. - When the Add button is pressed, the sum of values in the text fields are shown after the Equals: as a label. - The Clear button clears the values in the text fields and the result of the previous calculation. The cleared values can be blank or zero. - The Quit button closes the GUI window.arrow_forwardDice Simulator Create an application that simulates rolling a pair of dice. When the user clicks a button, the application should generate two random numbers, each in the range of 1 through 6, to represent the value of the dice. Use PictureBox controls to display the dice. (In the Student Sample Programs, in the Chap05 folder, you will find six images named Die1.bmp, Die2.bmp, Die3.bmp, Die4.bmp, Die5.bmp, and Die6.bmp that you can use in the PictureBoxes.)arrow_forwardFor this Mini-project, you need to create an application that allows the user to input two decimal numbers. The application should also have buttons that allow the user to request that the numbers are added, subtracted, multiplied, or divided. In addition, give an option to complete all 4 calculations or to clear the input and output (i.e., reset the page to its starting state). The program is written in C# in Visual Studio using the Web Form Design. Thank you!arrow_forward
- A software company sells a package that retails for $99. Quantity discounts are given according to the following table: Quantity Discount 10-19 10% 20-49 20% 50-99 30% 100 or more 40% Write a GUI program that asks the user to enter the number of packages purchased. The program should then display the amount of the discount (if any) and the total amount of the purchase after the discount. A successful test run of the program for different inputs is as shown below:arrow_forwardA county collects property taxes on the assessment value of property, which is 60 percent of the property's actual value. If an acre of land is valued at $10,000, its assessment value is $ 6,000. The property tax is then $0.64 for each $100 of the assessment value. The tax for the acre assessed at $6,000 will be $38.40. Create a GUI application that displays the assessment value and property tax when a user enters the actual value of a property. in Javaarrow_forwardproperty Tax in javaA county collects property taxes on the assessment value of property, which is 60 percent of the property’s actual value. If an acre of land is valued at $10,000, its assessment value is $6,000. The property tax is then $0.64 for each $100 of the assessment value. The tax for the acre assessed at $6,000 will be $38.40. Create a GUI application that displays the assess- ment value and property tax when a user enters the actual value of a property.arrow_forward
- Use Java Programming Language Write a GUI to calculate the number of servings that a circular pizza of a certain diameter will make. The GUI will have the following appearance: It must include the following features: The frame title must say 'Pizza Servings Calculator'. A grid layout will be used for the GUI. The JLabel title of the GUI will say 'Pizza Servings Calculator' and be in red and will be placed in grid slot 1. A JLabel of 'Enter the size of the pizza in inches: ' will be placed in grid slot 2 followed by a JTextField where the pizza size will be entered and have a width of 4. A JButton will be placed in grid slot 3 and will contain 'Calculate Servings'. A JLabel, initially blank, will be placed in grid slot 4. To execute the GUI, enter a pizza size in the JTextField and click the Calculate Servings button. The Calculate Servings button handler will then execute and calculate the number of servings and display it as shown in the following image: The number of…arrow_forwardShape1. Shape =5 will make the shape control appears as a rectangle O square O oval O rounded square Oarrow_forwardCreate an application with a form that resembles Figure 3-48. The PictureBox controls display the images of four fruits (a banana, an apple, an orange, and a pear) and each fruit’s calories. You can find these images in the Chap3 folder of the Student Sample Programs. When the application starts, the total calories should be zero. Each time the user clicks one of the PictureBoxes, the calories for the fruit should be added to the total calories, and the total calories should be displayed. When the user clicks the Reset button, the total calories should be reset to zero. Hello, I recently sent this question, but didn't provide images as needed. I apologize for that, I'm not sure how to upload the other three fruits (an apple, an orange, and a pear) since I can only upload two. If there is a way, please let me know. Just for clarification on this question, everytime the PictureBox (fruit) is clicked on, it will display the fruits calories on the label under "Total Calories", and…arrow_forward
- Write a tkinter application that asks the user to create their own pizza. First, they should enter their name. Then, allow them to pick one of three crusts (thin, regular, deep dish), one of three sauces (Regular, BBQ, Alfredo), and any number of 3 toppings (Pepperoni, Olives, Mushroom). They should also pick if they want a small, medium, or large pizza. When the submit button is clicked, calculate the total cost ($10 base price, $0.50 for each topping, and $1.50 for each increase in size larger than small). Once the total is calculated, display a messagebox that thanks the user (by name) for their order and prints out the total cost.arrow_forward02 - Rectangular Prisms Prompt the user for three integers representing the sides of a rectangular prism. Calculate the surface area and volume of the prism, then draw three rectangles of asterisks portraying the top, side, and front view of the prism labeled accordingly (which set of numbers represent each view is at your discretion). Enter three integers: 2 5 6 Surface Area: 104 Volume 60 Top View (2 x 5): Side View (2 x 6): Front View (5 x 6):arrow_forwardQuestion 1 Get room rate Room type single Number of night 3 Room rate 750.00 Get rate Close Figure 2: Get room rate GUI Write a complete program to create a graphical user interface (GUI) which calculate the room rate according to Table 1. The program should calculate and show the room rate in a text field which is not editable when the Get rate button is pressed and the system will be terminated when the Close button is pressed. The size of GUI should be set as 300 x 250. It should be shown in the centre of the screen and the program should shutdown when the user press the close button on the top right corner. Lastly, remember to create an object for the class in a main() method. Table 1: Hotel room rate according to room type Room type single Price in RM (per night) 250 double 320 suite 500arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT