首页 > 其他分享 >客户信息管理软件

客户信息管理软件

时间:2023-03-26 15:55:07浏览次数:26  
标签:return String 信息管理 System 客户 println 软件 public out

客户信息管理软件


CMUtility

        import java.util.Scanner;

        public class CMUtility {
            private static Scanner scanner = new Scanner(System.in);

            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("选择错误,请重新输入:");
                    } else break;
                }
                return c;
            }

            public static char readChar() {
                String str = readKeyBoard(1, false);
                return str.charAt(0);
            }

            public static char readChar(char defaultValue) {
                String str = readKeyBoard(1, true);
                return (str.length() == 0) ? defaultValue : str.charAt(0);
            }

            public static int readInt() {
                int n;
                for (; ; ) {
                    String str = readKeyBoard(2, false);
                    try {
                        n = Integer.parseInt(str);
                        break;
                    } catch (NumberFormatException e) {
                        System.out.print("数字输入错误,请重新输入:");
                    }
                }
                return n;
            }

            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("数字输入错误,请重新输入:");
                    }
                }
                return n;
            }

            public static String readString(int limit) {
                return readKeyBoard(limit, false);
            }

            public static String readString(int limit, String defaultValue) {
                String str = readKeyBoard(limit, true);
                return str.equals("")? defaultValue : str;
            }

            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("选择错误,请重新输入:");
                    }
                }
                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("输入长度(不大于" + limit + ")错误,请重新输入:");
                        continue;
                    }
                    break;
                }

                return line;
            }
        }

Customer

        /**
         * 客户类
         */
        public class Customer {
            private String name;
            private char gender;
            private int age;
            private String phone;
            private String email;

            public Customer() {

            }

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

            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;
            }
            
			//返回详细信息
            public String getDetails() {
                return name + "\t\t" + gender + "\t\t" + age + "\t\t" + phone + "\t\t" + email;
            }
        }

CustomerList

        /**
         * Customer的管理模块
         */
        public class CustomerList {
            private Customer[] customers;//保存Customer对象
            private int total = 0;//有效客户的数量

            /**
             * 初始化customers数组的容量
             * @param totalCustomer
             */
            public CustomerList(int totalCustomer) {
                customers = new Customer[totalCustomer];
            }

            /**
             * 添加客户
             * @param customer
             * @return
             */
            public boolean addCustomer(Customer customer) {
                if (total >= customers.length) {
                    return false;//数组已满
                }
                customers[total] = customer;
                total++;
                return true;//添加成功
            }

            /**
             * 修改客户
             * @param index
             * @param cust
             * @return
             */
            public boolean replaceCustomer(int index, Customer cust) {
                if (total < 0 || index >= total) {
                    return false;
                }
                customers[index] = cust;
                return true;
            }

            /**
             * 删除客户
             * @param index
             * @return
             */
            public boolean deleteCustomer(int index) {
                if (total < 0 || index >= total) {
                    return false;
                }
                for (int i = index; i < total - 1; i++) {
                    customers[i] = customers[i + 1];
                }
                customers[total - 1] = null;
                total--;
                return true;
            }

            /**
             * 返回有效元素的客户
             * @return
             */
            public Customer[] getAllCustomer() {
                Customer[] cuts = new Customer[total];
                for (int i = 0; i < cuts.length; i++) {
                    cuts[i] = customers[i];
                }
                return cuts;
            }

            /**
             * 返回客户对象的索引位置
             * @param index
             * @return
             */
            public Customer getCustomer(int index) {
                return customers[index];
            }

            public static void main(String[] args) {
                CustomerList cl = new CustomerList(5);
                Customer customer = new Customer("张三", '男', 18, "010-1234567", "[email protected]");
                boolean flag = cl.addCustomer(customer);
                if (flag) {
                    System.out.println("添加成功!");
                } else {
                    System.out.println("添加失败!");
                }

                Customer[] allCustomer = cl.getAllCustomer();
                for (Customer cust : allCustomer) {
                    System.out.println(cust.getDetails());
                }

            }
        }

CustomerView

        /**
         * 与用户进行交互
         */
        public class CustomerView {
            private CustomerList customerList = new CustomerList(10);

            public void enterMainMenu() {
                boolean loopFlag = true;
                do {
                    System.out.println("\n-----------------客户信息管理软件-----------------\n");
                    System.out.println("\t\t\t\t 1 添加客户");
                    System.out.println("\t\t\t\t 2 修改客户");
                    System.out.println("\t\t\t\t 3 删除客户");
                    System.out.println("\t\t\t\t 4 客户列表");
                    System.out.println("\t\t\t\t 5 退出");
                    System.out.println();
                    System.out.print("\t\t\t\t 请选择(1-5):");

                    char ch = CMUtility.readMenuSelection();
                    switch (ch) {
                        case '1':
                            //添加客户
                            addNewCustomer();
                            break;
                        case '2':
                            //修改客户
                            modifyCustomer();
                            break;
                        case '3':
                            //删除客户
                            deleteCustomer();
                            break;
                        case '4':
                            //客户列表
                            listAllCustomer();
                            break;
                        case '5':
                            //退出
                            System.out.print("是否退出(y/n):");
                            char c = CMUtility.readConfirmSelection();
                            if (c == 'Y') {
                                loopFlag = false;
                            }
                            break;
                    }
                } while (loopFlag);
            }

            /**
             * 添加
             */
            private void addNewCustomer() {
                System.out.println("\n---------------------添加客户---------------------\n");
                System.out.print("姓名:");
                String name = CMUtility.readString(20);

                System.out.print("性别:");
                char gender = CMUtility.readChar();

                System.out.print("年龄:");
                int age = CMUtility.readInt();

                System.out.print("电话:");
                String phone = CMUtility.readString(20);

                System.out.print("邮箱:");
                String emile = CMUtility.readString(20);

                //将散列的数据装进对象
                Customer customer = new Customer(name, gender, age, phone, emile);
                //将对象添加到数组中
                boolean flag = customerList.addCustomer(customer);
                if (flag) {
                    System.out.println("---------------------添加完成---------------------");
                } else {
                    System.out.println("---------------------添加失败---------------------");
                }
            }

            /**
             * 修改
             */
            private void modifyCustomer() {
                System.out.println("\n---------------------修改客户---------------------\n");
                Customer customer = null;
                int num = 0;

                while (true) {
                    System.out.print("请选择待修改客户编号(-1退出):");
                    num = CMUtility.readInt();
                    if (num == -1) {
                        return;//结束当前方法
                    }
                    customer = customerList.getCustomer(num - 1);
                    if (customer == null) {
                        System.out.println("无法找到指定客户!");
                    } else {
                        break;//结束这个死循环
                    }
                }
                //修改操作
                System.out.print("姓名(" + customer.getName() + "):");
                String name = CMUtility.readString(20, customer.getName());

                System.out.print("性别(" + customer.getGender() + "):");
                char gender = CMUtility.readChar(customer.getGender());

                System.out.print("年龄(" + customer.getAge() + "):");
                int age = CMUtility.readInt(customer.getAge());

                System.out.print("电话(" + customer.getPhone() + "):");
                String phone = CMUtility.readString(20, customer.getPhone());

                System.out.print("邮箱(" + customer.getEmail() + "):");
                String emile = CMUtility.readString(20, customer.getEmail());

                Customer cust = new Customer(name, gender, age, phone, emile);
                boolean flag = customerList.replaceCustomer(num - 1, cust);
                if (flag) {
                    System.out.println("---------------------修改完成---------------------");
                } else {
                    System.out.println("---------------------修改失败---------------------");
                }
            }

            /**
             * 删除
             */
            private void deleteCustomer() {
                System.out.println("\n---------------------删除客户---------------------\n");
                int num = 0;
                while (true) {
                    System.out.print("请选择待删除客户编号(-1退出):");
                    num = CMUtility.readInt();
                    if (num == -1) {
                        return;//结束当前方法
                    }
                    Customer cust = customerList.getCustomer(num - 1);
                    if (cust == null) {
                        System.out.println("无法找到客户信息!");
                    } else {
                        break;//结束这个死循环
                    }
                }
                //删除操作
                System.out.print("确认是否删除(Y/N):");
                char ch = CMUtility.readConfirmSelection();
                if (ch == 'N') {
                    return;//结束方法别删了
                }
                boolean flag = customerList.deleteCustomer(num - 1);
                if (flag) {
                    System.out.println("---------------------删除成功---------------------");
                } else {
                    System.out.println("---------------------删除失败---------------------");
                }
            }

            /**
             * 客户列表
             */
            private void listAllCustomer() {
                System.out.println("\n---------------------------客户列表---------------------------");

                Customer[] allCustomer = customerList.getAllCustomer();
                if (allCustomer.length == 0) {
                    System.out.println("无法找到信息!");
                } else {
                    System.out.println("编号\t姓名\t性别\t年龄\t电话\t\t邮箱");
                }
                for (int i = 0; i < allCustomer.length; i++) {
                    System.out.println((i + 1) + "\t" + allCustomer[i].getDetails());
                }
            }

            /**
             * 程序的入口
             *
             * @param args
             */
            public static void main(String[] args) {
                CustomerView cv = new CustomerView();
                cv.enterMainMenu();
            }
        }

标签:return,String,信息管理,System,客户,println,软件,public,out
From: https://www.cnblogs.com/yimengxunchen/p/17258823.html

相关文章

  • 软件测试--详细判断电话号码
    目录一、作业要求二、需求分析1、电话号码类型2、座机号码地点3、手机号码的种类常用运营商虚拟运营商号段物联网号段卫星电话号段其它号段4、手机地点5、国外号码6、测试......
  • [软件工程]代码调试方法 : 小黄鸭调试法 [转载]
    小黄鸭调试法(又称橡皮鸭调试法,黄鸭除虫法)是软件工程中使用的调试代码方法之一。此概念是参照于一个来自《程序员修炼之道》书中的一个故事。传说中程序编程大师......
  • 【电脑软件】网络端口被占用情况的解决方法
    使用XXX软件等,出现端口被占用的情况。如1080端口被占用可以通过管理员身份运行CMD查询并关闭占用的进程,并重新开启XXX软件。如下图所示:netstat-ano|findstr1080taskkil......
  • [软件设计] 软件系统总体结构设计 | 软件架构概述 [转载]
    1概述对于程序员而言,开始关注架构就是重大进步。就已经从单纯写代码的层次里跳了出来,至少从“增删改查”中跳了出来,能以更宏观的视角去思考代码、思考软件工程!这是一个......
  • 差生文具多:个人工作流软件梳理
    信息输入WPS便签:用来记录简短消息平台:Web端网页、Android端应用之前用菊花系手机时,自带云同步、分类功能的华为备忘录深得我心。换机后Moto没有自带同步的备忘录了,尝试......
  • buuctf 新年快乐、内涵的软件、xor
    内涵的软件下载解压文件后双击执行,没有任何提示将文件拖进exeinfope 发现查不出壳,并且为32位的文件,拖进ida32,shift+f12查找字符串,找到flag 新年快乐打开ida发......
  • 小众软件:录屏局部放大神器 ZoomIt
    ZoomIt功能屏幕放大录制工具说明此款软件解决了以下几点诉求:我们在录制软件使用教学的时候,有些操作位置细节的放大需要(局部放大)我们在给别人讲解PPT的时候,需要标注......
  • 2023年3月25日(软件工程日报)
    由于广播没指定唯一的接收者,因此可能存在多个接收器,每个接收器都拥有自己的处理逻辑。这种机制固然灵活,却不够严谨,因为不同接收器之间也许有矛盾。(1)一个广播存在多个接......
  • 陪诊软件开发多少钱,类似优享陪诊app开发,类似优享陪诊app开发多少钱,类似优享陪诊app开
       陪诊小程序怎么制作,陪诊软件开发多少钱,类似优享陪诊app开发,类似优享陪诊app开发多少钱,类似优享陪诊app开发贴牌,类似乐帮陪诊小程序开发,类似乐帮陪诊小程序开发多少......
  • es中几种客户端的理解
    在项目中,jestClient还有在使用,RestHighLevelClient没有怎么被使用。现在对其做一个对比,方便技术使用上方便切换。 一:JestClient1.说明JestClient是一款基于HT......