17

project--客户信息管理系统

 3 years ago
source link: http://www.cnblogs.com/xuanxiaokeji/p/13972426.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

软件设计分析

该软件有三个模块组成:Customer  CustomerList  CustomerView

Customer 为实体对象,用来封装客户信息;

CustomerList 为 Customer 对象的管理模块,内部用数组管理一组Customer 对象,并提供相应的增加,删除,修改和遍历方法,功CustomerView 调用;

CustomerView 为主模块,负责菜单的显示和处理用户操作;

一、Customer 类的设计

1、该类封装客户的信息

String name ; 客户姓名

String gender ; 性别

ing age ; 年龄

String phone ; 电话号码

String email ; 电子邮箱

2、提供个属性的get\set 方法

3、提供所需要的构造器

4、代码

package com.xuanxiao.customer;

/**
 * @see Customer为实体类,用来封装客户信息
 * @author mn Email:[email protected]
 * @version
 * @data 2020年11月11日
 */

public class Customer {
    
    private String name; //客户姓名
    private String gender; //性别
    private int age; //年龄
    private String phone; //电话号码
    private String email; //电子邮箱
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getGender() {
        return gender;
    }
    public void setGender(String 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;
    }
    public Customer() {
    }
    
    public Customer(String name, String gender, int age, String phone, String email) {
        this.name = name;
        this.gender = gender;
        this.age = age;
        this.phone = phone;
        this.email = email;
    }
        
}

二、CustomerList 类的设计

1、本类封装以下信息

Customer[] customers; 用来保存客户对象的数组

int total ; 记录已保存客户对象的数量

2、提供以下构造器和方法

public CustomerList(int totalCustomer)  ;用来初始化customers数组的构造器

public boolean addCustomer(Customer customer)  ;将指定的客户添加到数组中

public boolean replaceCustomer(int index,Customer cust)  ;修改指定索引位置的客户信息

public boolean deleteCustomer(int index)  ;删除指定位置的客户

public Customer[] getAllCustomers()  ;获取所有的客户信息

public Customer getCustomer(int index)  ;获取指定索引位置上的客户

public int getTotal()  ;获取存储的客户的数量

3、代码

package com.xuanxiao.server;

import com.xuanxiao.customer.Customer;

/**
 * @see CustomerList是Customer對象的管理模塊,内部使用Customer數組,並提供相應的添加,刪除,修改和遍歷操作。
 * @author mn Email:[email protected]
 * @version
 * @data 2020年11月11日
 *
 */


public class CustomerList {

    private Customer[] customers; //用来保存客户对象的数组
    private int total; //记录已保存客户对象的数量
    
    /**
     * @see 用来初始化customers数组的构造器
     * @param totleCoustmer:制定数组的长度的参数
     */
    public CustomerList(int totalCustomer) {
        customers = new Customer[totalCustomer];
    }
    /**
     * @see 将指定的客户添加到数组中
     * @author mn
     * @param customer
     * @return true:添加成功 false:添加失败
      */
    public boolean addCustomer(Customer customer) {
        
        if(total >= customers.length) {
            return false;
        }
        customers[total] = customer;
        total ++;
        
        //或者 customers[total++] = customer;
        return true;
    }
    
    /**
     * @see 修改指定索引位置的客户信息
     * @author mn
     * @param index
     * @param cust
     * @return true:修改成功 false:修改失败
     */
    public boolean replaceCustomer(int index,Customer cust) {
        
        if(index < 0 || index >= total) {
            return false;
        }else {
            customers[index] = cust;
            return true;
        }
    }
    
    /**
     * @see 删除指定位置的客户
     * @author mn
     * @param index
     * @return true:删除成功 false:删除失败
     */
    public boolean deleteCustomer(int index) {
        
        if(index < 0 || index >= total) {
            return false;
        }
        for(int i = index;i < total - 1;i++) {
            customers[i] = customers[i+1];
        }
        
        //最后一个有数据的元素置空
        customers[total-1] = null;
        total --;
        //或者 customers[--total] = null;
        return true;
    }
    
    /**
     * @see 获取所有的客户信息
     * @author mn
     * @return
     */
    public Customer[] getAllCustomers() {
        
        Customer[] custs = new Customer[total];
        for(int i = 0;i < total;i++) {
            custs[i] = customers[i];
        }
        return custs;
    }
    
    /**
     * @see 获取指定索引位置上的客户
     * @author mn
     * @param index
     * @return 找到元素返回;未找到返回null
     */
    public Customer getCustomer(int index) {
        
        if(index < 0 || index >= total) {
            return null;
        }
        return customers[index];
        
    }
    
    /**
     * @see 获取存储的客户的数量
     * @author mn
     * @return
     */
    public int getTotal() {
        return total;
    }
 }

三、CustomerView 类的设计

1、本类封装以下的信息

CustomerList customerList = new CustomerList[10] ;

2、提供以下的方法和构造器

public void enterMainView()  ;显示菜单

public void addNewCustomer()  ;增加客户信息

public void modifyCustomer()  ;修改客户信息

public void deleteCustomer()  ;删除客户信息

public void listAllCustomers()  ;遍历客户信息

public static void main(String[] args)  ;主函数

3、代码

package com.xuanxiao.view;

import java.util.Scanner;

import com.xuanxiao.customer.Customer;
import com.xuanxiao.server.CustomerList;

/**
 * @see CustomerView为主模块,负责菜单的显示和处理用户操作
 * @author mn Email:[email protected]
 * @version
 * @data 2020年11月11日
 */
public class CustomerView {

    private CustomerList customerList = new CustomerList(10);
    
    public CustomerView() {
        //Customer customer = new Customer("马成功", '男', 21, "17345625812", "[email protected]");
        //customerList.addCustomer(customer);
    }

    /**
     * @see 显示菜单
     */
    public void enterMainView() {

        boolean isFlag = true;
        while (isFlag) {
            System.out.println("----------客户信息管理软件----------");
            System.out.println("-           1. 添加客户                     -");
            System.out.println("-           2. 修改客户                     -");
            System.out.println("-           3. 删除客户                     -");
            System.out.println("-           4. 客户列表                     -");
            System.out.println("-           5. 退出系统                     -");
            System.out.println("-----------------------------------");
            System.out.println();
            System.out.print(" 请选择(1-5):");

            Scanner input = new Scanner(System.in);
            int choose;
            choose = input.nextInt();
            if (choose != 1 && choose != 2 && choose != 3 && choose != 4 && choose != 5) {
                System.out.println("输入信息有误,请重新输入!");
            }
            switch (choose) {
            case 1:
                addNewCustomer();
                break;
            case 2:
                modifyCustomer();
                break;
            case 3:
                deleteCustomer();
                break;
            case 4:
                listAllCustomers();
                break;
            case 5:
                System.out.print("确定是否退出(退出11/不退00):");
                Scanner input1 = new Scanner(System.in);
                int exit;
                exit = input1.nextInt();
                if (exit == 11) {
                    isFlag = false;
                }
            }

        }

    }

    /**
     * @see 添加客户的操作
     */
    public void addNewCustomer() {
//        System.out.println("添加客户的操作");
        System.out.println("-----------------客户列表------------------");
        Scanner scanner = new Scanner(System.in);
        System.out.print("姓名:");
        String name;
        name = scanner.nextLine();
        System.out.print("性别:");
        String gender;
        gender = scanner.nextLine();
        System.out.print("年龄:");
        Scanner scanner1 = new Scanner(System.in);
        int age;
        age = scanner1.nextInt();
        System.out.print("电话号码:");
        String phone;
        phone = scanner.nextLine();
        System.out.print("邮箱:");
        String email;
        email = scanner.nextLine();
        
        //将上面的数据封装到对象中
        Customer customer = new Customer(name,gender,age,phone,email);
        boolean isSuccess = customerList.addCustomer(customer);
        if(isSuccess) {
            System.out.println("-----------------添加完成------------------");
        }else {
            System.out.println("-----------------目录已满,添加失败--- -----");
        }
    }

    /**
     * @see 修改客户的操作
     */
    public void modifyCustomer() {
//        System.out.println("修改客户的操作");
        System.out.println("-----------------添加完成------------------");
        Customer cust;
        int number;
        for (;;) {
            System.out.println("请选择待修改的客户编号(-1退出):");
            Scanner input = new Scanner(System.in);
            
            number = input.nextInt();
            if (number == -1) {
                return;
            }
            cust = customerList.getCustomer(number-1);
            if(cust == null) {
                System.out.println("无法找到指定的客户!");
            }else {
                break;
            }
        }
        //找到了指定的客户,修改客户信息
        Scanner input = new Scanner(System.in);
        Scanner input1 = new Scanner(System.in);
        System.out.println("姓名(" + cust.getName() + "):");
        String name;
        name = input.nextLine();
        System.out.println("性别(" + cust.getGender() + "):");
        String gender;
        gender = input.nextLine();
        System.out.println("年龄(" + cust.getAge() + "):");
        int age;
        age = input1.nextInt();
        System.out.println("电话号码(" + cust.getPhone() + "):");
        String phone;
        phone = input.nextLine();
        System.out.println("邮箱(" + cust.getEmail() + "):");
        String email;
        email = input.nextLine();
        
        Customer newcust = new Customer(name, gender, age, phone, email);
        boolean isReplace = customerList.replaceCustomer(number-1, newcust);
        if(isReplace) {
            System.out.println("-----------------修改完成------------------");
        }else {
            System.out.println("-----------------修改失败------------------");
        }
        
    }

    /**
     * @see 删除客户的操作
     */
    public void deleteCustomer() {
//        System.out.println("删除客户的操作");
        System.out.println("-----------------删除客户------------------");
        Scanner input = new Scanner(System.in);
        int number;
        for (;;) {
            System.out.println("请选择待修改的客户编号(-1退出):");
            number = input.nextInt();
            if (number == -1) {
                return;
            }
            Customer cust = customerList.getCustomer(number-1);
            if(cust == null) {
                System.out.println("无法找到指定的客户!");
            }else {
                break;
            }
        }
        //找到指定的客户,删除操作
        System.out.println("是否确认删除(删除11/不删00):");
        int number1;
        number1 = input.nextInt();
        if(number1 == 00) {
            return;
        }else {
            boolean isDelete = customerList.deleteCustomer(number - 1);
            if(isDelete) {
                System.out.println("-----------------删除成功------------------");
            }else {
                System.out.println("-----------------删除失败------------------");
            }
        }
        
    }

    /**
     * @see 显示客户的列表
     */
    public void listAllCustomers() {
        //System.out.println("显示客户的列表");
        System.out.println("-----------------客户列表------------------");
        
        int total = customerList.getTotal();
        if(total == 0) {
            System.out.println("没有客户记录!!");
        }else {
            System.out.println("编号\t姓名\t性别\t年龄\t电话\t\t邮箱");
            Customer[] custs = customerList.getAllCustomers();
            for(int i = 0;i < total;i++) {
                Customer cust = custs[i];
                System.out.println((i+1) + "\t" + cust.getName() + "\t" + cust.getGender() + "\t"
                + cust.getAge() + "\t" + cust.getPhone() + "\t" + cust.getEmail());
                
            }
        } 
        
        System.out.println("---------------客户列表完成----------------");
    }

    public static void main(String[] args) {

        CustomerView view = new CustomerView();
        view.enterMainView();

    }
}

四、总结

1、代码有冗余

2、可添加一个工具类对输入进行约束

3、增加用户体验

4、链接数据库,对数据进行持久化保存

五、快捷键

注释:本人使用的是eclipse,   可使用里面的快捷键加快开发效率

1、补全代码的声明:alt + /

2、快速修复:ctrl + 1

3、批量导包:crat + shift + o

4、使用单行注释:ctrl + /

5、使用多行注释:crtl + shift + /

6、取消多行注释:ctrl + shift + \

7、复制指定行的代码:ctrl + alt + down 或者 ctrl + alt + up

8、删除指定行的代码:ctrl + d

9、上下移动代码:alt + up 或者  alt + down

10、切换到下一行代码空位:shift + enter

11、切换到上一行代码空位:ctrl + shift + enter

12、查看源代码:ctrl + 选中指定的结构  或者  ctrl + shift + t

13、退回到前一个编辑页面:alt + left

14、进入到下一个编辑页面:alt + right

15、选中指定的类,查看继承树结构:ctrl + t

16、复制代码:ctrl + c

17、撤销:ctrl + z

18、反撤销:ctrl + y

19、剪切:ctrl + x

20、粘贴:ctrl + v

21、保存:ctrl + s

22、全选:ctrl + a

23、格式化代码:ctrl + shift + f

24、选中数行,整体向后移动:tab

25、选中数行,整体向前移动:shift + tab

26、在当前类中,显示类结构,并支持搜索指定的方法、属性等:ctrl + o

27、批量修改指定的方法名、变量名、类名等:alt + shift + r

28、选中的结构大小写切换,变成大写:ctrl + shift + x

29、选中的结构大小写切换,变成小写:ctrl + shift + y

30、调出getter/setter构造器等结构:alt + shift + s

31、显示当前选择资源(工程 or 文件)的属性:alt + enter

32、快速查找,参照选中的word快速定位到下一个:ctrl + k

33、关闭当前窗口:ctrl + w

34、关闭所有窗口:ctrl + shift + w

35、查看指定的结构使用过的地方:ctrl + alt + g

36、查找与替换:ctrl + f

37、最大化当前的View:ctrl + m

38、直接定位到当前行的首行:home

39、直接定位到当前行的末行:end


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK