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

DO NOT CODE IN MAIN incorporate GUI components of JTextField, JTextArea and JBut

ID: 3872080 • Letter: D

Question

DO NOT CODE IN MAIN

incorporate GUI components of JTextField, JTextArea and JButton with the following requirements.

The application should calculate the cost of the meal order based on an adult meal and child meal. The user will input a four digit identification code for the school, the number of adult meals and child meals each in separate text fields. (You will have 3 text fields). After the interface is displayed and the user has completed the entry for the purchase, display the School ID, the the number of adult meals and the number of child meals. The charge is calculated using adult meal costing $7.00 and child meal costing $3.50. Accumulate the total charge for all of the meals and the number of meals sold and display each of these last 2 items in individual labels.

Interface Layout and Input

Include the fictitious name of charity as a label at the top of your frame, displaying the charity name in a larger font than the rest of the fields in the interface.

Include the following labeled text fields for user input:

School-identification code (a four-digit code)

Meals—one text field for adult meal and another text field for child meal

Include a button to trigger the calculations and display the results. Also allow for the last text field to trigger the calculations and display.

Include a text area for displaying the results of the current order.

Include individual labels for both the total accumulated meal charges for all orders and the total number of meals processed for all orders.

Include a label at the bottom of the interface containing your name as the developer.

Processing

After the user has input the School ID code, the number of adult meals and the number of child meals and calculate the cost of the order based on $7.00 for adult meal and $3.50 for the child meal.

Accumulate the total (adult and child) meals charges for all orders entered and the number of meals (adult and child meals) processed. (Note: Assume for each user processing is only one order)

You must use constants for the adult meal of 7.00 and the child meal of 3.50.

Output

Display the School ID, the adult and child meal formatted to include a dollar sign and 2 decimal place. Sample Data below and the meal charge in the text area.

Display the total shipping charges for all packages and the number of packages processed in individual labels .

School Code Wa78

Adult Meal 3

Child Meal 2

Total Cost $28.00

Other Requirements

You must ensure that you do not code your entire application in the main method. Use a constructor to build the user interface and the actionPerformed method of the ActionListener interface to respond to the user’s entry and do the calculations needed. You may break the task into more methods than described above, if you prefer.

Also, try to use the setSize method of the JFrame to position your fields so that the interface is readable (labels next to the matching text fields, etc. Use constants for the width and height of the frame. Remember that you can also help to determine the size of your components when you declare them. Extra spaces in a label or button could help to line up items for a better interface look.

Sample Data Calculation

Test Data (Input)

Check Figures (Answer)

School ID

Meals

Meal Charge

Wa78

3 Adult. 2 Child .

$28.00

Explanation / Answer

this is the MainClass.java file

package chegg;

public class MainClass {

   public static void main(String[] args) {
       Calc c = new Calc();
       c.setVisible(true);
   }

}

this is Calc.java file

package chegg;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class Calc extends JFrame{

   JLabel Id_label,adult_meal_label,child_meal_label,total_cost_label,charity_name,current_order;
   JTextField Id_txt,adlt_ml_txt,child_ml_txt,total_cost_txt;
   JButton submit_btn;
   JTextArea display_current_order;
  
   String school_code;
   double ad_ml,ch_ml,tot;
  
   public Calc() {
       super("Meal Cost Calculator");
       setLayout(null);
       setSize(500, 500);
       charity_name = new JLabel("CHARITY NAME");
       charity_name.setFont(new Font("Serif",Font.BOLD,25));
       charity_name.setBounds(125, 25, 300, 100);
      
       Id_label = new JLabel("School Code");
       Id_label.setBounds(50, 100, 100, 30);
      
       adult_meal_label = new JLabel("Adult meal");
       adult_meal_label.setBounds(50, 150, 100, 30);
      
       child_meal_label = new JLabel("Child Meal");
       child_meal_label.setBounds(50, 200, 100, 30);
      
       total_cost_label = new JLabel("Total Cost");
       total_cost_label.setBounds(50, 250, 100, 30);
      
       Id_txt = new JTextField();
       Id_txt.setBounds(150, 100, 100, 30);
      
       adlt_ml_txt = new JTextField();
       adlt_ml_txt.setBounds(150, 150, 100, 30);
      
       child_ml_txt = new JTextField();
       child_ml_txt.setBounds(150, 200, 100, 30);
      
       total_cost_txt = new JTextField();
       total_cost_txt.setBounds(150, 250, 100, 30);
       total_cost_txt.setEnabled(false);
      
       submit_btn = new JButton("Calculate");
       submit_btn.setBounds(200, 300, 100, 30);
      
       display_current_order = new JTextArea();
       display_current_order.setBounds(150, 350, 200, 100);
      
       current_order = new JLabel("Current Order");
       current_order.setBounds(50, 350, 100, 30);
      
       submit_btn.addActionListener(new ActionListener() {
          
           @Override
           public void actionPerformed(ActionEvent arg0) {
               // TODO Auto-generated method stub
               school_code = Id_txt.getText();
               ad_ml = Double.parseDouble(adlt_ml_txt.getText());
               ch_ml = Double.parseDouble(child_ml_txt.getText());
               tot = ad_ml*7+ch_ml*3.5;
               total_cost_txt.setText("$ "+String.valueOf(tot));
               display_current_order.setText("School Code "+school_code+" "
                       +"Adult Meal "+ad_ml+" "+"Child Meal "+ch_ml+" "+
                       "Total Cost $"+tot);
           }
       });
      
       add(charity_name);
       add(Id_label);
       add(adult_meal_label);
       add(child_meal_label);
       add(total_cost_label);
       add(Id_txt);
       add(adlt_ml_txt);
       add(child_ml_txt);
       add(total_cost_txt);
       add(submit_btn);
       add(display_current_order);
       add(current_order);
   }
  
}