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

Operation This application begins by displaying a table of customer data. If the

ID: 3576558 • Letter: O

Question

Operation

This application begins by displaying a table of customer data.

If the user clicks the Add button, the application allows the user to add customer data to the table (and the underlying database).

If the user selects a customer row and clicks the Edit button, the application allows the user to update the data for the selected customer row in the table (and the database).

If the user selects a customer row and clicks the Delete button, the application deletes the selected customer row from the table (and the database).

Specifications

Create a Database to store the persons email, firstname, and lastname

Create a class named Customer that stores data for the user’s id, email address, first name, and last name.

Create a class named CustomerDB that contains the methods necessary to get an array list of Customer objects, to get a Customer object for the customer with the specified id, and to add, update, or delete the specified customer.

Create a CustomerManagerFrame class like the one shown above. This frame should display a table of customer data as well as the Add, Edit, and Delete buttons. This class should use the Customer and CustomerDB classes to work with the customer data.

Create a CustomerForm class that allows the user to add or edit customer data.

Create Customer (GUI) Customer Manager Email First Name Last Name frankiones Cyahoo.com John Smith johnsmith chotmail.com seagreen clevi.com ynthia Green Kowolski wendykCwarners.com endy Add Edit Delete

Explanation / Answer

Hello,

I could not complete the whole Project

Please took the base code with some errors and Understand

Customer.java

---------------------------


public class Customer {
  
   int id ;
   String email = "";
   //String address;
   String first_name = "";
   String last_name = "";
   public Customer(String fn, String ln,String email){
       this.first_name = fn;
       this.last_name = ln;
       this.email = email;
   }
}

CustomerDB.java

------------------------------

import java.util.ArrayList;


public class CustomerDB {
    ArrayList<Customer> customers = new ArrayList<Customer>();
  
    public void addCustomer(Customer c){
       customers.add(c);  
    }
  
    public Customer getCustomer(int id){
       for(int i = 0 ; i < customers.size();i++){
           if(customers.get(i).id == id){
               return customers.get(i);
           }
       }
       return null;
    }
  
    public void updateCustomer(Customer c){
       for(int i = 0 ; i < customers.size();i++){
           if(customers.get(i).id == c.id){
               customers.remove(i);
               customers.add(i, c);
           }
       }  
    }
    public void deleteCustomer(int index){
      
               customers.remove(index);
              
          
    }
  
    public ArrayList<Customer> getCustomers(){
       return customers;
    }
}

CustomerForm.java

-----------------------------------

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;


public class CustomerForm extends JFrame implements ActionListener{
   private JLabel fNameL, lNameL, emailL;
   private JTextField fNameEdit, lNameEdit, emailEdit;
   private JButton btnSave;
   CustomerDB db;
   Customer currentEditCustomer;
   public CustomerForm(CustomerDB db , Customer c){
      
       this.db = db;
       this.currentEditCustomer = c;
       fNameL = new JLabel("Enter First Name: ", SwingConstants.RIGHT);
       lNameL = new JLabel("Enter Last Name: ", SwingConstants.RIGHT);
       emailL = new JLabel("Enter E-Mail: ", SwingConstants.RIGHT);
      
       fNameEdit = new JTextField(30);
       lNameEdit = new JTextField(30);
       emailEdit = new JTextField(30);
      
       //SPecify handlers for each button and add (register) ActionListeners to each button.
       btnSave = new JButton("Save");
       btnSave.addActionListener(this);
      
       setTitle("SCustomer Entry Form");
       Container pane = getContentPane();
       pane.setLayout(new GridLayout(3, 2));
      
       //Add things to the pane in the order you want them to appear (left to right, top to bottom)
               pane.add(fNameL);
               pane.add(fNameEdit);
              
               pane.add(lNameL);
               pane.add(lNameEdit);
              
               pane.add(emailL);
               pane.add(emailEdit);
              
               this.add(btnSave);
               //setSize(WIDTH, HEIGHT);
               setVisible(true);
               setDefaultCloseOperation(EXIT_ON_CLOSE);
   }
   @Override
   public void actionPerformed(ActionEvent e) {
       // TODO Auto-generated method stub
       //Add New Customer
       if(currentEditCustomer == null){
           Customer c = new Customer(CustomerForm.this.fNameEdit.getSelectedText(),
                                     CustomerForm.this.lNameEdit.getText(),
                                     CustomerForm.this.emailEdit.getText());
           db.addCustomer(c);
       }
       //Edit Existing Customer
       else{
           db.updateCustomer(currentEditCustomer) ;
       }
       CustomerForm.this.setVisible(false);
     
   }
}

CustomerManagerFrame.java :-

------------------------------------------

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;


public class CustomerManagerFrame extends JFrame implements ActionListener, ComponentListener{
   CustomerDB db;
   //headers for the table
    String[] columns = new String[] {
        "E-Mail", "First Name", "Last Name"
    };
    JTable table;
    JButton jbnAdd, jbnEdit, jbnDelete;
    DefaultTableModel model;
    public CustomerManagerFrame(CustomerDB db){
       this.db = db;
       model = new DefaultTableModel();
       table = new JTable(model);
       model.addColumn(columns[0]);
       model.addColumn(columns[1]);
       model.addColumn(columns[2]);
       table = new JTable();
       //add the table to the frame
        this.add(new JScrollPane(table));
      
      
        for(int i = 0 ; i < db.getCustomers().size() ; i++){
           model.addRow(new Object[]{db.getCustomers().get(i).first_name,
                                      db.getCustomers().get(i).last_name,
                                      db.getCustomers().get(i).email});
        }
        this.setTitle("Table Example");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     
        this.pack();
        Container pane = getContentPane();
       pane.setLayout(new GridLayout(1, 3));
        jbnAdd = new JButton("Add");
        jbnAdd.addActionListener(this);
        pane.add(jbnAdd);
      
        jbnEdit = new JButton("Edit");
        jbnEdit.addActionListener(this);
        pane.add(jbnEdit);
      
        jbnDelete = new JButton("Delete");
        jbnDelete.addActionListener(this);
        pane.add(jbnDelete);
        this.addComponentListener(this);
        this.setVisible(true);
    }

   @Override
   public void actionPerformed(ActionEvent e) {
       // TODO Auto-generated method stub
       if ("Add".equals(e.getActionCommand())) {
            new CustomerForm(db, null);
       }
       else if ("Edit".equals(e.getActionCommand())){
           int selIndex = CustomerManagerFrame.this.table.getSelectedRow();
           Customer selCustomer = db.getCustomers().get(selIndex);  
           new CustomerForm(db, selCustomer);
       }
       else{
           int selIndex = CustomerManagerFrame.this.table.getSelectedRow();
           db.deleteCustomer(selIndex);
          
       }
   }

   @Override
   public void componentResized(ComponentEvent e) {
       // TODO Auto-generated method stub
      
   }

   @Override
   public void componentMoved(ComponentEvent e) {
       // TODO Auto-generated method stub
      
   }

   @Override
   public void componentShown(ComponentEvent e) {
       if(table == null){
           return;
       }
       // TODO Auto-generated method stub
       //DefaultTableModel model = (DefaultTableModel) table.getModel();
      
        for(int i = 0 ; i < db.getCustomers().size() ; i++){
           model.removeRow(i);
           model.addRow(new Object[]{db.getCustomers().get(i).first_name,
                                      db.getCustomers().get(i).last_name,
                                      db.getCustomers().get(i).email});
        }  
   }

   @Override
   public void componentHidden(ComponentEvent e) {
       // TODO Auto-generated method stub
      
   }
  
}

CustomerDemo.java

-----------------------------------


public class CustomerDemo {

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
        CustomerManagerFrame form = new CustomerManagerFrame(new CustomerDB());
   }

}

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