Customer management system

Keywords: html css

catalogue

1, Learning objectives

  2, Requirement description

3, Software design structure  

  4, Project sketch and activity diagram

  5, Experimental steps

5.1CMUtility class

  5.2Customer class

5.3CustomerView class

    5.3.1 main page

  5.3.2 adding and viewing student pages

  5.3.3 delete student page

  5.3.4 modify student page  

  5.3.5 exit page

1, Learning objectives

  2, Requirement description

Simulate the implementation of customer information management software based on text interface.

The software can insert, modify and delete customer objects (realized by array), and print customer details.

The project adopts hierarchical menu mode. The main menu is as follows:

             ----------------- Customer information management software-----------------

                                     1 add customer

                                     2. Modify customer

                                     3 delete customer

                                     4 customer list

                                     5 retreat            Out

                                     Please select (1-5):_

• the information of each Customer is saved in the Customer object.
• record all current customers in an array of Customer type.
• after each "add Customer" (menu 1), the Customer object is added to the array.
• after each "modify Customer" (menu 2), the modified Customer object replaces the original object in the array.
• after each "delete Customer" (menu 3), the Customer object is cleared from the array.
• when executing "customer list" (menu 4), the information of all customers in the array will be listed.  

  The interface and operation process of "add customer" are as follows:

  ......

                   Please select (1-5): 1

---------------------Add customer---------------------

Name: Tong Gang

Gender: Male

Age: 35

Tel: 010-56253825

Email: tongtong@atguigu.com

---------------------Add complete---------------------

The interface and operation process of "modify customer" are as follows:

  ......

                   Please select (1-5): 2

---------------------Modify customer---------------------

Please select the customer number to be modified (- 1 exit): 1

Name (Tong Gang): < enter directly means no modification >

Gender (male):

Age (35):

Tel (010-56253825):

Mailbox( tongtong@atguigu.com): tongg@atguigu.com

---------------------Modification completed---------------------

The interface and operation process of "delete customer" are as follows:

  ......

                   Please select (1-5): 3

---------------------Delete customer---------------------

Please select the customer number to be deleted (- 1 exit): 1

Confirm delete (Y/N): y

---------------------Delete complete---------------------

The interface and operation process of "customer list" are as follows:

  ......

   Please select (1-5): 4

---------------------------Customer list---------------------------

number   full name        Gender     Age    Telephone                    mailbox

  one     Tong Gang          male         forty-five      010-56253825    tong@abc.com

  two     Feng Jie          female         thirty-six      010-56253825    fengjie@ibm.com

  three     Lei Fengyang      male         thirty-two       010-56253825    leify@163.com

-------------------------Customer list complete-------------------------

3, Software design structure  

The software consists of the following three modules:

  •   CustomerView is the main module, which is responsible for menu display and user operation
  • CustomerList is the management module of Customer objects. It internally uses an array to manage a group of Customer objects, and provides corresponding addition, modification, deletion and traversal methods for CustomerView to call
  • Customer is an entity object used to encapsulate customer information

  4, Project sketch and activity diagram

 

  5, Experimental steps

5.1CMUtility class

Note: This is a tool class and can be called directly.

import java.util.Scanner;

/**
 CMUtility Tools:
 Encapsulating different functions into methods means that its functions can be used directly by calling methods without considering the specific function implementation details.
 */
public class CMUtility {
    private static Scanner scanner = new Scanner(System.in);
    /**
     Used to select the interface menu. This method reads the keyboard. If the user types any character in '1' - '5', the method returns. The return value is the character typed by the user.
     */
    public static char readMenuSelection() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false);
            c = str.charAt(0);
            if (c != '1' && c != '2' &&
                    c != '3' && c != '4' && c != '5') {
                System.out.print("Selection error, please re-enter:");
            } else break;
        }
        return c;
    }
    /**
     Read a character from the keyboard and use it as the return value of the method.
     */
    public static char readChar() {
        String str = readKeyBoard(1, false);
        return str.charAt(0);
    }
    /**
     Read a character from the keyboard and use it as the return value of the method.
     If the user enters directly without entering characters, the method will take defaultValue as the return value.
     */
    public static char readChar(char defaultValue) {
        String str = readKeyBoard(1, true);
        return (str.length() == 0) ? defaultValue : str.charAt(0);
    }
    /**
     Read an integer with a length of no more than 2 bits from the keyboard and take it as the return value of the method.
     */
    public static int readInt() {
        int n;
        for (; ; ) {
            String str = readKeyBoard(2, false);
            try {
                n = Integer.parseInt(str);
                break;
            } catch (NumberFormatException e) {
                System.out.print("Digital input error, please re-enter:");
            }
        }
        return n;
    }
    /**
     Read an integer with a length of no more than 2 bits from the keyboard and take it as the return value of the method.
     If the user enters directly without entering characters, the method will take defaultValue as the return value.
     */
    public static int readInt(int defaultValue) {
        int n;
        for (; ; ) {
            String str = readKeyBoard(2, true);
            if (str.equals("")) {
                return defaultValue;
            }

            try {
                n = Integer.parseInt(str);
                break;
            } catch (NumberFormatException e) {
                System.out.print("Digital input error, please re-enter:");
            }
        }
        return n;
    }
    /**
     Read a string whose length does not exceed limit from the keyboard and take it as the return value of the method.
     */
    public static String readString(int limit) {
        return readKeyBoard(limit, false);
    }
    /**
     Read a string whose length does not exceed limit from the keyboard and take it as the return value of the method.
     If the user enters directly without entering characters, the method will take defaultValue as the return value.
     */
    public static String readString(int limit, String defaultValue) {
        String str = readKeyBoard(limit, true);
        return str.equals("")? defaultValue : str;
    }
    /**
     The input used to confirm the selection. This method reads' Y 'or' N 'from the keyboard and takes it as the return value of the method.
     */
    public static char readConfirmSelection() {
        char c;
        for (; ; ) {
            String str = readKeyBoard(1, false).toUpperCase();
            c = str.charAt(0);
            if (c == 'Y' || c == 'N') {
                break;
            } else {
                System.out.print("Selection error, please re-enter:");
            }
        }
        return c;
    }

    private static String readKeyBoard(int limit, boolean blankReturn) {
        String line = "";

        while (scanner.hasNextLine()) {
            line = scanner.nextLine();
            if (line.length() == 0) {
                if (blankReturn) return line;
                else continue;
            }

            if (line.length() < 1 || line.length() > limit) {
                System.out.print("Input length (not greater than)" + limit + ")Error, please re-enter:");
                continue;
            }
            break;
        }

        return line;
    }
}

  5.2Customer class

 

Code display:  

public class Customer {
    private int sid;
    private String name;
    private char gender;
    private int age;
    private String phone;
    private String email;

    public Customer() {

    }

    public Customer(int sid, String name, char gender, int age, String phone, String email) {
        this.sid = sid;
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.phone = phone;
        this.email = email;
    }


    public int getSid() {
        return sid;
    }

    public void setSid(int sid) {
        this.sid = sid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}

  Tip: this step is not difficult. You can use the shortcut key: AIt+Insert

5.3CustomerView class

    5.3.1 main page

  Code display:

public class CustomerManager {
    public static void main(String[] args) {
        ArrayList<Customer> array = new ArrayList<Customer>();
      /*  Customer people = new Customer("Tong Gang "," male ", 35," 56253825 " tongtong@atguigu.com ");
        array.add(people);*/
        int total = 0;
        boolean isFlag = true;
       
        while (isFlag) {
            System.out.println(" -----------------Customer information management software-----------------");
            System.out.println("                   1 Add customer");
            System.out.println("                   2 Modify customer");
            System.out.println("                   3 Delete customer");
            System.out.println("                   4 Customer list");
            System.out.println("                   5 retreat      Out");
            System.out.println("                   Please select(1-5): ");
            Scanner sc = new Scanner(System.in);
            char menu = CMUtility.readMenuSelection();
            switch (menu) {
                case '1':
                    addCustomer(array);
                    break;
                case '2':
                    setCustomer(array,total);
                    break;
                case '3':
                   deleteCustomer(array);
                    total++;
                    break;
                case '4':
                    checkCustomer(array);
                    break;
                case '5': {
                    System.out.print("Confirm whether to exit(Y/N): ");
                    char exit = CMUtility.readConfirmSelection();
                    if (exit == 'Y') {
                        isFlag = false;
                        System.out.println("Exit successful");
                        break;
                    } else {
                        System.out.println("Exit failed");
                    }
                }
            }
        }
    }

Note: the code of this page is relatively regular and not too difficult. Note that I define int total=0, because the number will change after deleting members in this item.

  5.3.2 adding and viewing student pages

  Code display:

public static void addCustomer(ArrayList<Customer> array) {
        System.out.println("---------------------Add customer---------------------");
        Scanner sc = new Scanner(System.in);
        System.out.println("Please enter customer number:" + (array.size()+ 1));
        int sid = sc.nextInt();
        System.out.print("full name:");
        String name = CMUtility.readString(5);
        System.out.print("Gender:");
        char gender = CMUtility.readChar();
        System.out.print("Age:");
        int age = CMUtility.readInt();
        System.out.print("Telephone:");
        String phone = CMUtility.readString(15);
        System.out.print("Email:");
        String email = CMUtility.readString(20);

        Customer one = new Customer();
        one.setSid(sid);
        one.setName(name);
        one.setGender(gender);
        one.setAge(age);
        one.setPhone(phone);
        one.setEmail(email);

        array.add(one);
        if (array.size() <= 10) {
            System.out.println("--------Add complete--------");
        } else {
            System.out.println("The collection is full and cannot be added");
        }

    }

    public static void checkCustomer(ArrayList<Customer> array) {
        System.out.println("--------Customer list--------");
        System.out.println("number\t full name\t Gender\t Age\t\t Telephone\t\t mailbox");
        if (array.size() == 0) {
            System.out.println("No customer records");
        } else {
            for (int i = 0; i < array.size(); i++) {
                Customer list = array.get(i);
                System.out.println(list.getSid() + "\t" + list.getName() + "\t" + list.getGender() + "\t" + list.getAge() + "\t" + list.getPhone() + "\t" + list.getEmail());
            }
            System.out.println("--------Customer list complete--------");
        }
    }

Note: 1. Understand   CMUtility tool class, and then call it.

            2. Judge in advance whether the data in the set is full and whether the customer list has records.

  5.3.3 delete student page

Code display:  

public static void deleteCustomer(ArrayList<Customer> array) {
        System.out.println("---------Delete customer--------");
        System.out.println("Please select the customer number to be deleted(-1 sign out): ");
        Scanner sc = new Scanner(System.in);
        int sid = sc.nextInt();
        if (sid == -1) {
            return;
        } else {
            System.out.println("Are you sure you want to delete(Y/N): ");
            char selection = CMUtility.readConfirmSelection();
            ArrayList<Customer> Newarray = new ArrayList<Customer>();
            for (int i = 0; i < array.size(); i++) {
                Customer D = array.get(i);
                if (selection == 'N') {
                    Newarray = array;
                } else {
                    array.remove(i);
                    for (int j = 0; j < array.size(); j++) {
                        Customer D1 = array.get(j);
                        Newarray.add(D1);
                    }
                    if (selection == 'N' || D.getSid() != sid) {
                        System.out.println("--------Deletion failed--------");
                        System.out.println("Please re-enter the function and number");
                        break;
                    } else {
                        System.out.println("--------Delete succeeded--------");
                    }


                }


            }


        }
    }

Note: when entering the customer number, the number is not - 1 or does not exist, which needs to be judged.  

  5.3.4 modify student page  

Code display:  

 public static void setCustomer(ArrayList<Customer> array, int total) {


            ArrayList<Customer> New = new ArrayList<Customer>();
            for (int i = 0; i < array.size(); i++){
                Scanner sc = new Scanner(System.in);
                System.out.println("Please select the customer number to be modified(-1 sign out): ");
                int sid = sc.nextInt();
                Customer C=array.get(i);
                if(C.getSid() == sid){


                    if (sid == -1 || sid < 0 || sid > (array.size() + 1)) {
                        System.out.println("Modification failed, please re-enter");
                    } else {

                        System.out.println("full name" + "(" + array.get(sid - 1 - total).getName() + "):");
                        String name = CMUtility.readString(4,C.getName());


                        System.out.println("Gender" + "(" + array.get(sid - 1 - total).getGender() + "):");
                        char gender = CMUtility.readChar(C.getGender());

                        System.out.println("Age" + "(" + array.get(sid - 1 - total).getAge() + "):");
                        int age = CMUtility.readInt(C.getAge());

                        System.out.println("Telephone" + "(" + array.get(sid - 1 - total).getPhone() + "):");
                        String phone = CMUtility.readString(15,C.getPhone());

                        System.out.println("mailbox" + "(" + array.get(sid - 1 - total).getEmail() + "):");
                        String email = CMUtility.readString(20,C.getEmail());


                    C.setName(name);
                    C.setGender(gender);
                    C.setAge(age);
                    C.setPhone(phone);
                    C.setEmail(email);
                    New.add(C);
                }
            }

        }

        System.out.println("--------Modified successfully--------");
    }

  Note: pay special attention to the detail that pressing enter does not modify it! I didn't have such an operation before. In the optimization process, I added this operation and reported errors many times in the process, because I couldn't find the right object. You can try it.

  5.3.5 exit page

Posted by oprpg on Sat, 20 Nov 2021 09:09:01 -0800