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

The objective of the assignment is to write a GUI app using check boxes and comb

ID: 3805610 • Letter: T

Question

The objective of the assignment is to write a GUI app using check boxes and combo boxes to create GUI objects. INSTRUCTIONS: Cindy's catering provides meals for parties and special events. Create an interactive GUI program that allows Cindy's Catering to better operate their business. The following data must be entered concerning the customer and the event: The customer's name must be entered into a text field. The customer's contact phone number into a text field. The number of guests invited to a Cindy catered event into a text field. The customer must choose one entree from a group of at least four choices. The customer must choose up to two side dishes from a group of at least four choices. The customer must choose one desert from a group of at least three choices. Display the cost of the event which is calculated as $35 per person. To validate the input data, do the following: If the value entered for the number of guest is not numeric, set the event price to zero. If the user attempts to choose more than two side dishes, remove all the current side dish selections so that the user can start over. After the final price for the dinner has been calculated, the event information must be saved to an output file so that Cindy's Catering will have the information for the event. The items should be separated by spaces. If any item is not chosen, enter the word "none" for that item. The following fields must be written to the output file. the customer's name the customer's contact phone number the number of guests the one entree chosen the two sides chosen the one desert chosen Requirements: The data input must be done with a GUI. The GUI must be defined in a programmer-defined class, named Catering.java, rather than in the main class The main class, named Cindy.java, should instantiate the class Catering. The output file should be named Event.txt.

Explanation / Answer

// I hope this is helpful.

//Let me know if you have any doubts, I will try my best to explain.

//Cindy.java

package cindy;

public class Cindy {

public static void main(String[] args) {
Catering catering = new Catering();
}
  
}

//Catering.java


package cindy;

import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;

public class Catering
{
public JFrame mainFrame;
private JPanel controlPanel;
JCheckBox checkBox1 = null; JCheckBox checkBox2 = null;
JCheckBox checkBox3 = null; JCheckBox checkBox4 = null;
  
Catering()
{
controlPanel = new JPanel();
mainFrame = new JFrame("Cindy's Catering");
mainFrame.setSize(600,600);
mainFrame.setLayout(new GridLayout(3, 1));
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});   
//Design and reposition the components the way you want it to look
JLabel cname_l = new JLabel();
//cname_l.setLayout(new FlowLayout(FlowLayout.CENTER));
cname_l.setText("Customer's Name: ");
JTextField cname_t = new JTextField(20);
JLabel pnumber_l = new JLabel();
pnumber_l.setText("Customer's Phone No.: ");
JTextField pnumber_t = new JTextField(20);
JLabel guest_l = new JLabel();
guest_l.setText("No. of guests: ");
JTextField guest_t = new JTextField(20);
JLabel entree_l = new JLabel();
entree_l.setText("Select entree: ");
String entree[]={"Entree 1","Entree 2","Entree 3","Entree 4"};
JComboBox entree_cb = new JComboBox(entree);
JLabel sdish_l = new JLabel();
sdish_l.setText("Side dishes(choose any 2): ");
//validate check boxes each time its selected for all checkboxes
checkBox1 = new JCheckBox("Side Dish 1");
checkBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
validateCheckBox();
}
});
checkBox2 = new JCheckBox("Side Dish 2");
checkBox2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
validateCheckBox();
}
});
checkBox3 = new JCheckBox("Side Dish 3");
checkBox3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
validateCheckBox();
}
});
checkBox4 = new JCheckBox("Side Dish 4");
checkBox4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
validateCheckBox();
}
});
JLabel desert_l = new JLabel();
desert_l.setText("Select desert: ");
String desert[]={"Desert 1","Desert 2","Desert 3"};
JComboBox desert_cb = new JComboBox(desert);
JButton goButton = new JButton("Go");
goButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
calculate(guest_t.getText()); //pass all the form parameters here
}
});
//controlPanel.setLayout(new FlowLayout(controlPanel,BoxLayout.Y_AXIS));
controlPanel.add(cname_l); controlPanel.add(cname_t);
controlPanel.add(pnumber_l); controlPanel.add(pnumber_t);
controlPanel.add(guest_l); controlPanel.add(guest_t);
controlPanel.add(entree_l); controlPanel.add(entree_cb);
controlPanel.add(sdish_l); controlPanel.add(checkBox1);
controlPanel.add(checkBox2);controlPanel.add(checkBox3);
controlPanel.add(checkBox4);controlPanel.add(goButton);
controlPanel.add(desert_l); controlPanel.add(desert_cb);
mainFrame.add(controlPanel);
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
}
  
public void calculate(String guests)//receive all the form patrameters and validate
{
if (!guests.matches("[0-9]+")) {
JOptionPane.showMessageDialog(null, "Total cost of the event: $0");
}else{
int total_cost = Integer.parseInt(guests) * 35;
JOptionPane.showMessageDialog(null, "Total cost of the event: $"+total_cost);
}
  
//To do
//Write the form details to file here (to do)
}
public void validateCheckBox()
{
int countSelection = 0;
ArrayList<JCheckBox> buttons = new ArrayList<>();
buttons.add(checkBox1);
buttons.add(checkBox2);
buttons.add(checkBox3);
buttons.add(checkBox4);
for ( JCheckBox checkbox : buttons ) {
if( checkbox.isSelected() )
{
countSelection++;
}
}
if(countSelection > 2)
{
checkBox1.setSelected(false); checkBox2.setSelected(false);
checkBox3.setSelected(false); checkBox4.setSelected(false);
}
}
}

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