{"id":681,"date":"2022-10-04T22:49:22","date_gmt":"2022-10-04T14:49:22","guid":{"rendered":"https:\/\/qaqaq.top\/?p=681"},"modified":"2022-11-27T12:39:57","modified_gmt":"2022-11-27T04:39:57","slug":"%e9%a1%b9%e7%9b%ae%e4%ba%8c-%e5%ae%a2%e6%88%b7%e4%bf%a1%e6%81%af%e7%ae%a1%e7%90%86%e8%bd%af%e4%bb%b6-%e5%a4%8d%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=681","title":{"rendered":"\u9879\u76ee\u4e8c \u5ba2\u6237\u4fe1\u606f\u7ba1\u7406\u8f6f\u4ef6 \u590d\u4e60"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P259.bean;\r\n\r\n\/**\r\n * \r\n * @Description Customer\u4e3a\u5b9e\u4f53\u7c7b\uff0c\u7528\u6765\u5c01\u88c5\u5ba2\u6237\u4fe1\u606f\r\n * @author RichieZhang Email:18358892@qq.com\r\n * @version\r\n * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53485:08:49\r\n *\r\n *\/\r\npublic class Customer {\r\n\r\n\tprivate String name; \/\/ \u5ba2\u6237\u59d3\u540d\r\n\tprivate char gender; \/\/ \u6027\u522b\r\n\tprivate int age; \/\/ \u5e74\u9f84\r\n\tprivate String phone; \/\/ \u7535\u8bdd\u53f7\u7801\r\n\tprivate String email; \/\/ \u7535\u5b50\u90ae\u4ef6\r\n\r\n\tpublic Customer() {\r\n\r\n\t}\r\n\r\n\tpublic Customer(String name, char gender, int age, String phone, String email) {\r\n\t\tthis.name = name;\r\n\t\tthis.gender = gender;\r\n\t\tthis.age = age;\r\n\t\tthis.phone = phone;\r\n\t\tthis.email = email;\r\n\t}\r\n\r\n\tpublic String getName() {\r\n\t\treturn name;\r\n\t}\r\n\r\n\tpublic void setName(String name) {\r\n\t\tthis.name = name;\r\n\t}\r\n\r\n\tpublic char getGender() {\r\n\t\treturn gender;\r\n\t}\r\n\r\n\tpublic void setGender(char gender) {\r\n\t\tthis.gender = gender;\r\n\t}\r\n\r\n\tpublic int getAge() {\r\n\t\treturn age;\r\n\t}\r\n\r\n\tpublic void setAge(int age) {\r\n\t\tthis.age = age;\r\n\t}\r\n\r\n\tpublic String getPhone() {\r\n\t\treturn phone;\r\n\t}\r\n\r\n\tpublic void setPhone(String phone) {\r\n\t\tthis.phone = phone;\r\n\t}\r\n\r\n\tpublic String getEmail() {\r\n\t\treturn email;\r\n\t}\r\n\r\n\tpublic void setEmail(String email) {\r\n\t\tthis.email = email;\r\n\t}\r\n\t\r\n\tpublic String getDetails() {\r\n\t\treturn name + \"\\t\" + gender + \"\\t\" + age + \"\\t\" + phone + \"\\t\" + email;\r\n\t}\r\n\r\n\/\/\tpublic static void main(String&#91;] args) {\r\n\/\/\t\tCustomer cust = new Customer(\"\u5f20\u4e09\", '\u7537', 23, \"12323233232\", \"12323233232@qq.com\");\r\n\/\/\t\tSystem.out.println(\"\u59d3\u540d\uff1a\" + cust.getName() + \", \u6027\u522b\uff1a\" + cust.getGender() + \", \u5e74\u9f84\uff1a\" + cust.getAge() + \", \u7535\u8bdd\u53f7\u7801\uff1a\" + cust.getPhone() + \", \u7535\u5b50\u90ae\u4ef6\uff1a\" + cust.getEmail());\r\n\/\/\t}\r\n\r\n}\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P259.seriver;\r\n\r\nimport top.qaqaq.java.P259.bean.Customer;\r\n\r\n\/**\r\n * \r\n * @Description CustomerList\u4e3aCustomer\u5bf9\u8c61\u7684\u7ba1\u7406\u6a21\u5757\uff0c\r\n *              \u5185\u90e8\u4f7f\u7528\u6570\u7ec4\u7ba1\u7406\u4e00\u7ec4Customer\u5bf9\u8c61\uff0c\u5e76\u63d0\u4f9b\u76f8\u5e94\u7684\u6dfb\u52a0\u3001\u4fee\u6539\u3001\u5220\u9664\u548c\u904d\u5386\u65b9\u6cd5\uff0c \u4f9bCustomerView\u8c03\u7528\r\n * @author RichieZhang Email:18358892@qq.com\r\n * @version\r\n * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53485:09:25\r\n *\r\n *\/\r\npublic class CustomerList {\r\n\r\n\tprivate Customer&#91;] customers; \/\/ \u7528\u6765\u4fdd\u5b58\u5ba2\u6237\u5bf9\u8c61\u7684\u6570\u7ec4\r\n\tprivate int total = 0; \/\/ \u8bb0\u5f55\u5df2\u4fdd\u5b58\u5ba2\u6237\u5bf9\u8c61\u7684\u6570\u91cf\r\n\r\n\t\/**\r\n\t * \u7528\u6765\u521d\u59cb\u5316customers\u6570\u7ec4\u7684\u6784\u9020\u5668\r\n\t * \r\n\t * @param totalCustomer \u6307\u5b9a\u6570\u7ec4\u7684\u957f\u5ea6\r\n\t *\/\r\n\tpublic CustomerList(int totalCustomer) {\r\n\r\n\t\tcustomers = new Customer&#91;totalCustomer];\r\n\t}\r\n\r\n\t\/**\r\n\t * \r\n\t * @Description \u5c06\u6307\u5b9a\u7684\u5ba2\u6237\u6dfb\u52a0\u5230\u6570\u7ec4\u4e2d\r\n\t * @author RichieZhang\r\n\t * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53485:11:59\r\n\t * @param customer\r\n\t * @return true:\u6dfb\u52a0\u6210\u529f falst:\u6dfb\u52a0\u5931\u8d25\r\n\t *\/\r\n\tpublic boolean addCustomer(Customer customer) {\r\n\r\n\t\tif (total >= customers.length) {\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tcustomers&#91;total++] = customer;\r\n\t\treturn true;\r\n\t}\r\n\r\n\t\/**\r\n\t * \r\n\t * @Description \u4fee\u6539\u6307\u5b9a\u7d22\u5f15\u4f4d\u7f6e\u7684\u5ba2\u6237\u4fe1\u606f\r\n\t * @author RichieZhang\r\n\t * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53485:12:29\r\n\t * @param index\r\n\t * @param cust\r\n\t * @return true:\u4fee\u6539\u6210\u529f false:\u4fee\u6539\u5931\u8d25\r\n\t *\/\r\n\tpublic boolean replaceCustomer(int index, Customer cust) {\r\n\r\n\t\tif (index &lt; 0 || index >= total) {\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tcustomers&#91;index] = cust;\r\n\t\treturn true;\r\n\t}\r\n\r\n\t\/**\r\n\t * \r\n\t * @Description \u5220\u9664\u6307\u5b9a\u7d22\u5f15\u4f4d\u7f6e\u4e0a\u7684\u5ba2\u6237\r\n\t * @author RichieZhang\r\n\t * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53485:12:54\r\n\t * @param index\r\n\t * @return true:\u5220\u9664\u6210\u529f false:\u5220\u9664\u5931\u8d25\r\n\t *\/\r\n\tpublic boolean deleteCustomer(int index) {\r\n\r\n\t\tif (index &lt; 0 || index >= total) {\r\n\t\t\treturn false;\r\n\t\t}\r\n\r\n\t\tfor (int i = index; i &lt; total - 1; i++) {\r\n\t\t\tcustomers&#91;i] = customers&#91;i + 1];\r\n\t\t}\r\n\r\n\t\tcustomers&#91;--total] = null;\r\n\t\treturn true;\r\n\t}\r\n\r\n\t\/**\r\n\t * \r\n\t * @Description \u83b7\u53d6\u6240\u6709\u7684\u5ba2\u6237\u4fe1\u606f\r\n\t * @author RichieZhang\r\n\t * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53485:13:14\r\n\t * @return\r\n\t *\/\r\n\tpublic Customer&#91;] getAllCustomers() {\r\n\r\n\t\tCustomer custs&#91;] = new Customer&#91;total];\r\n\t\tfor (int i = 0; i &lt; total; i++) {\r\n\t\t\tcusts&#91;i] = customers&#91;i];\r\n\t\t}\r\n\r\n\t\treturn custs;\r\n\t}\r\n\r\n\t\/**\r\n\t * \r\n\t * @Description \u83b7\u53d6\u6307\u5b9a\u7d22\u5f15\u4f4d\u7f6e\u4e0a\u7684\u5ba2\u6237\r\n\t * @author RichieZhang\r\n\t * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53485:13:36\r\n\t * @param index\r\n\t * @return \u5982\u679c\u627e\u5230\u4e86\u5143\u7d20\uff0c\u5219\u8fd4\u56de\uff1b\u5982\u679c\u6ca1\u6709\u627e\u5230\uff0c\u5219\u8fd4\u56denull\r\n\t *\/\r\n\tpublic Customer getCustomer(int index) {\r\n\r\n\t\tif (index &lt; 0 || index >= total) {\r\n\t\t\treturn null;\r\n\t\t}\r\n\r\n\t\treturn customers&#91;index];\r\n\t}\r\n\r\n\t\/**\r\n\t * \r\n\t * @Description \u83b7\u53d6\u5b58\u50a8\u7684\u5ba2\u6237\u7684\u6570\u91cf\r\n\t * @author RichieZhang\r\n\t * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53485:13:51\r\n\t * @return\r\n\t *\/\r\n\tpublic int getTotal() {\r\n\r\n\t\treturn total;\r\n\r\n\t}\r\n\r\n\/\/\tpublic static void main(String&#91;] args) {\r\n\/\/\t\tCustomerList custs = new CustomerList(5);\r\n\/\/\t\t\r\n\/\/\t\tCustomer customer = new Customer();\r\n\/\/\t\tCustomer customer1 = new Customer(\"\u5f20\u4e09\", '\u7537', 23, \"12323233232\", \"12323233232@qq.com\");\r\n\/\/\t\tCustomer customer2 = new Customer(\"\u674e\u56db\", '\u7537', 23, \"12323233232\", \"12323233232@qq.com\");\r\n\/\/\t\tCustomer customer3 = new Customer(\"\u738b\u4e94\", '\u7537', 23, \"12323233232\", \"12323233232@qq.com\");\r\n\/\/\t\tCustomer customer4 = new Customer(\"\u8001\u516d\", '\u7537', 23, \"12323233232\", \"12323233232@qq.com\");\r\n\/\/\t\tCustomer customer5 = new Customer(\"\u83b1\u4e03\", '\u7537', 23, \"12323233232\", \"12323233232@qq.com\");\r\n\/\/\t\tcusts.addCustomer(customer1);\r\n\/\/\t\tcusts.addCustomer(customer2);\r\n\/\/\t\tcusts.addCustomer(customer3);\r\n\/\/\t\tcusts.addCustomer(customer4);\r\n\/\/\t\tcusts.addCustomer(customer5);\r\n\/\/\r\n\/\/\t\tfor (int i = 0; i &lt; custs.total; i++) {\r\n\/\/\t\t\tSystem.out.println(custs.customers&#91;i].getDetails());\r\n\/\/\t\t}\r\n\/\/\t\t\r\n\/\/\t\tSystem.out.println(\"\u6709\" + custs.getTotal() + \"\u4e2a\u5ba2\u6237\");\r\n\/\/\t\tSystem.out.println(\"******************************************\");\r\n\/\/\t\t\r\n\/\/\t\tCustomer test = new Customer(\"\u4f60\u597d\", '\u7537', 23, \"12323233232\", \"12323233232@qq.com\");\r\n\/\/\t\t\r\n\/\/\t\tcusts.replaceCustomer(3, test);\r\n\/\/\t\tfor (int i = 0; i &lt; custs.total; i++) {\r\n\/\/\t\t\tSystem.out.println(custs.customers&#91;i].getDetails());\r\n\/\/\t\t}\r\n\/\/\t\tSystem.out.println(\"******************************************\");\r\n\/\/\t\t\r\n\/\/\t\tcusts.deleteCustomer(2);\r\n\/\/\t\tfor (int i = 0; i &lt; custs.total; i++) {\r\n\/\/\t\t\tSystem.out.println(custs.customers&#91;i].getDetails());\r\n\/\/\t\t}\r\n\/\/\t\tSystem.out.println(\"******************************************\");\r\n\/\/\t\t\r\n\/\/\t\tSystem.out.println(custs.getCustomer(3).getDetails());\r\n\/\/\t\tSystem.out.println(\"******************************************\");\r\n\/\/\t\t\r\n\/\/\t\tSystem.out.println(\"\u6709\" + custs.getTotal() + \"\u4e2a\u5ba2\u6237\");\r\n\/\/\t\tSystem.out.println(\"******************************************\");\r\n\/\/\t\t\r\n\/\/\t\tSystem.out.println(custs.getAllCustomers());\r\n\/\/\r\n\/\/\t}\r\n\r\n}\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P259.ui;\r\n\r\nimport top.qaqaq.java.P259.bean.Customer;\r\nimport top.qaqaq.java.P259.seriver.CustomerList;\r\nimport top.qaqaq.java.P259.util.CMUtility;\r\n\r\n\/**\r\n * \r\n * @Description CustomerView\u4e3a\u4e3b\u6a21\u5757\uff0c\u8d1f\u8d23\u83dc\u5355\u7684\u663e\u5f0f\u548c\u5904\u7406\u7528\u6237\u64cd\u4f5c\r\n * @author RichieZhang Email:18358892@qq.com\r\n * @version\r\n * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53488:25:45\r\n *\r\n *\/\r\npublic class CustomerView {\r\n\r\n\tCustomerList customerList = new CustomerList(10);\r\n\r\n\tpublic CustomerView() {\r\n\t\tCustomer customer = new Customer(\"\u738b\u6d9b\", '\u7537', 23, \"13212341234\", \"wt@gmail.com\");\r\n\t\tcustomerList.addCustomer(customer);\r\n\t}\r\n\r\n\t\/**\r\n\t * \r\n\t * @Description \u663e\u793a\u300a\u5ba2\u6237\u4fe1\u606f\u7ba1\u7406\u8f6f\u4ef6\u300b\u754c\u9762\u7684\u65b9\u6cd5\r\n\t * @author RichieZhang\r\n\t * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53488:26:03\r\n\t *\/\r\n\tpublic void enterMainMenu() {\r\n\r\n\t\tboolean isFlag = true;\r\n\r\n\t\twhile (isFlag) {\r\n\t\t\tSystem.out.println(\"-----------------\u5ba2\u6237\u4fe1\u606f\u7ba1\u7406\u8f6f\u4ef6-----------------\\n\");\r\n\t\t\tSystem.out.println(\"                   1 \u6dfb \u52a0 \u5ba2 \u6237\");\r\n\t\t\tSystem.out.println(\"                   2 \u4fee \u6539 \u5ba2 \u6237\");\r\n\t\t\tSystem.out.println(\"                   3 \u5220 \u9664 \u5ba2 \u6237\");\r\n\t\t\tSystem.out.println(\"                   4 \u5ba2 \u6237 \u5217 \u8868\");\r\n\t\t\tSystem.out.println(\"                   5 \u9000       \u51fa\\n\");\r\n\t\t\tSystem.out.print(\"                   \u8bf7\u9009\u62e9(1-5)\uff1a\");\r\n\r\n\t\t\tchar menu = CMUtility.readMenuSelection();\r\n\t\t\tswitch (menu) {\r\n\r\n\t\t\tcase '1':\r\n\t\t\t\taddNewCustomer();\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase '2':\r\n\t\t\t\tmodifyCustomer();\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase '3':\r\n\t\t\t\tdeleteCustomer();\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase '4':\r\n\t\t\t\tlistAllCustomers();\r\n\t\t\t\tbreak;\r\n\r\n\t\t\tcase '5':\r\n\t\t\t\tSystem.out.println(\"\u786e\u8ba4\u662f\u5426\u9000\u51fa(Y\/N)\uff1a\");\r\n\t\t\t\tchar isExit = CMUtility.readConfirmSelection();\r\n\t\t\t\tif (isExit == 'Y') {\r\n\t\t\t\t\tisFlag = false;\r\n\t\t\t\t}\r\n\r\n\/\/\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t}\r\n\r\n\t\/**\r\n\t * \r\n\t * @Description \u6dfb\u52a0\u5ba2\u6237\u7684\u64cd\u4f5c\r\n\t * @author RichieZhang\r\n\t * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53488:26:27\r\n\t *\/\r\n\tprivate void addNewCustomer() {\r\n\r\n\t\tSystem.out.println(\"---------------------\u6dfb\u52a0\u5ba2\u6237---------------------\");\r\n\r\n\t\tSystem.out.print(\"\u59d3\u540d\uff1a\");\r\n\t\tString name = CMUtility.readString(10);\r\n\t\tSystem.out.print(\"\u6027\u522b\uff1a\");\r\n\t\tchar gender = CMUtility.readChar();\r\n\t\tSystem.out.print(\"\u5e74\u9f84\uff1a\");\r\n\t\tint age = CMUtility.readInt();\r\n\t\tSystem.out.print(\"\u7535\u8bdd\uff1a\");\r\n\t\tString phone = CMUtility.readString(13);\r\n\t\tSystem.out.print(\"\u90ae\u7bb1\uff1a\");\r\n\t\tString email = CMUtility.readString(30);\r\n\r\n\t\tCustomer customer = new Customer(name, gender, age, phone, email);\r\n\r\n\t\tboolean isSussess = customerList.addCustomer(customer);\r\n\t\tif (isSussess) {\r\n\t\t\tSystem.out.println(\"---------------------\u6dfb\u52a0\u5b8c\u6210---------------------\");\r\n\t\t} else {\r\n\t\t\tSystem.out.println(\"----------------\u5ba2\u6237\u76ee\u5f55\u5df2\u6ee1\uff0c\u6dfb\u52a0\u5931\u8d25----------------\");\r\n\t\t}\r\n\t}\r\n\r\n\t\/**\r\n\t * \r\n\t * @Description \u4fee\u6539\u5ba2\u6237\u7684\u64cd\u4f5c\r\n\t * @author RichieZhang\r\n\t * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53488:26:47\r\n\t *\/\r\n\tprivate void modifyCustomer() {\r\n\r\n\t\tSystem.out.println(\"---------------------\u4fee\u6539\u5ba2\u6237---------------------\");\r\n\r\n\t\tCustomer cust;\r\n\t\tint number;\r\n\r\n\t\tfor (;;) {\r\n\t\t\tSystem.out.print(\"\u8bf7\u9009\u62e9\u5f85\u4fee\u6539\u5ba2\u6237\u7f16\u53f7(-1\u9000\u51fa)\uff1a\");\r\n\t\t\tnumber = CMUtility.readInt();\r\n\t\t\tif (number == -1) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tcust = customerList.getCustomer(number - 1);\r\n\r\n\t\t\tif (cust == null) {\r\n\t\t\t\tSystem.out.print(\"\u65e0\u6cd5\u627e\u5230\u6307\u5b9a\u5ba2\u6237\uff01\");\r\n\t\t\t} else {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tSystem.out.print(\"\u59d3\u540d(\" + cust.getName() + \")\uff1a\");\r\n\t\tString name = CMUtility.readString(10, cust.getName());\r\n\t\tSystem.out.print(\"\u6027\u522b(\" + cust.getGender() + \")\uff1a\");\r\n\t\tchar gender = CMUtility.readChar(cust.getGender());\r\n\t\tSystem.out.print(\"\u5e74\u9f84(\" + cust.getAge() + \")\uff1a\");\r\n\t\tint age = CMUtility.readInt(cust.getAge());\r\n\t\tSystem.out.print(\"\u7535\u8bdd(\" + cust.getPhone() + \")\uff1a\");\r\n\t\tString phone = CMUtility.readString(13, cust.getPhone());\r\n\t\tSystem.out.print(\"\u90ae\u7bb1(\" + cust.getEmail() + \")\uff1a\");\r\n\t\tString email = CMUtility.readString(30, cust.getEmail());\r\n\r\n\t\tCustomer newCust = new Customer(name, gender, age, phone, email);\r\n\r\n\t\tboolean isRepalaced = customerList.replaceCustomer(number - 1, newCust);\r\n\t\tif (isRepalaced) {\r\n\t\t\tSystem.out.println(\"---------------------\u4fee\u6539\u5b8c\u6210---------------------\");\r\n\t\t} else {\r\n\t\t\tSystem.out.println(\"---------------------\u4fee\u6539\u5931\u8d25---------------------\");\r\n\t\t}\r\n\t}\r\n\r\n\t\/**\r\n\t * \r\n\t * @Description \u5220\u9664\u5ba2\u6237\u7684\u64cd\u4f5c\r\n\t * @author RichieZhang\r\n\t * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53488:26:59\r\n\t *\/\r\n\tprivate void deleteCustomer() {\r\n\r\n\t\tSystem.out.println(\"---------------------\u5220\u9664\u5ba2\u6237---------------------\");\r\n\r\n\t\tint number;\r\n\t\tfor (;;) {\r\n\t\t\tSystem.out.println(\"\u8bf7\u9009\u62e9\u5f85\u5220\u9664\u5ba2\u6237\u7f16\u53f7(-1\u9000\u51fa)\uff1a\");\r\n\t\t\tnumber = CMUtility.readInt();\r\n\r\n\t\t\tif (number == -1) {\r\n\t\t\t\treturn;\r\n\t\t\t}\r\n\r\n\t\t\tCustomer customer = customerList.getCustomer(number - 1);\r\n\r\n\t\t\tif (customer == null) {\r\n\t\t\t\tSystem.out.println(\"\u65e0\u6cd5\u627e\u5230\u6307\u5b9a\u5ba2\u6237\uff01\");\r\n\t\t\t} else {\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\r\n\t\t}\r\n\t\t\r\n\t\tSystem.out.print(\"\u786e\u8ba4\u662f\u5426\u5220\u9664(Y\/N)\uff1a\");\r\n\t\tchar isDelete = CMUtility.readConfirmSelection();\r\n\t\tif (isDelete == 'Y') {\r\n\t\t\tboolean deleteSuccess = customerList.deleteCustomer(number - 1);\r\n\t\t\tif (deleteSuccess) {\r\n\t\t\t\tSystem.out.println(\"---------------------\u5220\u9664\u5b8c\u6210---------------------\");\r\n\t\t\t} else {\r\n\t\t\t\tSystem.out.println(\"---------------------\u5220\u9664\u5931\u8d25---------------------\");\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\treturn;\r\n\t\t}\r\n\r\n\t}\r\n\r\n\t\/**\r\n\t * \r\n\t * @Description \u663e\u793a\u5ba2\u6237\u5217\u8868\u7684\u64cd\u4f5c\r\n\t * @author RichieZhang\r\n\t * @date 2022\u5e7410\u67084\u65e5\u4e0b\u53488:27:14\r\n\t *\/\r\n\tprivate void listAllCustomers() {\r\n\r\n\t\tSystem.out.println(\"---------------------------\u5ba2\u6237\u5217\u8868---------------------------\");\r\n\r\n\t\tint total = customerList.getTotal();\r\n\t\tif (total == 0) {\r\n\t\t\tSystem.out.println(\"\u6ca1\u6709\u5ba2\u6237\u8bb0\u5f55\uff01\");\r\n\t\t} else {\r\n\t\t\tSystem.out.println(\"\u7f16\u53f7\\t\u59d3\u540d\\t\u6027\u522b\\t\u5e74\u9f84\\t\u7535\u8bdd\\t\\t\u90ae\u7bb1\");\r\n\t\t\tCustomer&#91;] custs = customerList.getAllCustomers();\r\n\t\t\tfor (int i = 0; i &lt; total; i++) {\r\n\t\t\t\tCustomer cust = custs&#91;i];\r\n\t\t\t\tSystem.out.println(i + 1 + \"\\t\" + cust.getName() + \"\\t\" + cust.getGender() + \"\\t\" + cust.getAge() + \"\\t\"\r\n\t\t\t\t\t\t+ cust.getPhone() + \"\\t\" + cust.getEmail());\r\n\t\t\t}\r\n\r\n\t\t}\r\n\r\n\t\tSystem.out.println(\"-------------------------\u5ba2\u6237\u5217\u8868\u5b8c\u6210-------------------------\");\r\n\t}\r\n\r\n\tpublic static void main(String&#91;] args) {\r\n\r\n\t\tCustomerView view = new CustomerView();\r\n\t\tview.enterMainMenu();\r\n\t}\r\n\r\n}\r\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P259.util;\r\n\r\n\r\nimport java.util.*;\r\n\/**\r\nCMUtility\u5de5\u5177\u7c7b\uff1a\r\n\u5c06\u4e0d\u540c\u7684\u529f\u80fd\u5c01\u88c5\u4e3a\u65b9\u6cd5\uff0c\u5c31\u662f\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u8c03\u7528\u65b9\u6cd5\u4f7f\u7528\u5b83\u7684\u529f\u80fd\uff0c\u800c\u65e0\u9700\u8003\u8651\u5177\u4f53\u7684\u529f\u80fd\u5b9e\u73b0\u7ec6\u8282\u3002\r\n*\/\r\npublic class CMUtility {\r\n    private static Scanner scanner = new Scanner(System.in);\r\n    \/**\r\n\t\u7528\u4e8e\u754c\u9762\u83dc\u5355\u7684\u9009\u62e9\u3002\u8be5\u65b9\u6cd5\u8bfb\u53d6\u952e\u76d8\uff0c\u5982\u679c\u7528\u6237\u952e\u5165\u20191\u2019-\u20195\u2019\u4e2d\u7684\u4efb\u610f\u5b57\u7b26\uff0c\u5219\u65b9\u6cd5\u8fd4\u56de\u3002\u8fd4\u56de\u503c\u4e3a\u7528\u6237\u952e\u5165\u5b57\u7b26\u3002\r\n\t*\/\r\n\tpublic static char readMenuSelection() {\r\n        char c;\r\n        for (; ; ) {\r\n            String str = readKeyBoard(1, false);\r\n            c = str.charAt(0);\r\n            if (c != '1' &amp;&amp; c != '2' &amp;&amp; \r\n                c != '3' &amp;&amp; c != '4' &amp;&amp; c != '5') {\r\n                System.out.print(\"\u9009\u62e9\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff1a\");\r\n            } else break;\r\n        }\r\n        return c;\r\n    }\r\n\t\/**\r\n\t\u4ece\u952e\u76d8\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002\r\n\t*\/\r\n    public static char readChar() {\r\n        String str = readKeyBoard(1, false);\r\n        return str.charAt(0);\r\n    }\r\n\t\/**\r\n\t\u4ece\u952e\u76d8\u8bfb\u53d6\u4e00\u4e2a\u5b57\u7b26\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002\r\n\t\u5982\u679c\u7528\u6237\u4e0d\u8f93\u5165\u5b57\u7b26\u800c\u76f4\u63a5\u56de\u8f66\uff0c\u65b9\u6cd5\u5c06\u4ee5defaultValue \u4f5c\u4e3a\u8fd4\u56de\u503c\u3002\r\n\t*\/\r\n    public static char readChar(char defaultValue) {\r\n        String str = readKeyBoard(1, true);\r\n        return (str.length() == 0) ? defaultValue : str.charAt(0);\r\n    }\r\n\t\/**\r\n\t\u4ece\u952e\u76d8\u8bfb\u53d6\u4e00\u4e2a\u957f\u5ea6\u4e0d\u8d85\u8fc72\u4f4d\u7684\u6574\u6570\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002\r\n\t*\/\r\n    public static int readInt() {\r\n        int n;\r\n        for (; ; ) {\r\n            String str = readKeyBoard(2, false);\r\n            try {\r\n                n = Integer.parseInt(str);\r\n                break;\r\n            } catch (NumberFormatException e) {\r\n                System.out.print(\"\u6570\u5b57\u8f93\u5165\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff1a\");\r\n            }\r\n        }\r\n        return n;\r\n    }\r\n\t\/**\r\n\t\u4ece\u952e\u76d8\u8bfb\u53d6\u4e00\u4e2a\u957f\u5ea6\u4e0d\u8d85\u8fc72\u4f4d\u7684\u6574\u6570\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002\r\n\t\u5982\u679c\u7528\u6237\u4e0d\u8f93\u5165\u5b57\u7b26\u800c\u76f4\u63a5\u56de\u8f66\uff0c\u65b9\u6cd5\u5c06\u4ee5defaultValue \u4f5c\u4e3a\u8fd4\u56de\u503c\u3002\r\n\t*\/\r\n    public static int readInt(int defaultValue) {\r\n        int n;\r\n        for (; ; ) {\r\n            String str = readKeyBoard(2, true);\r\n            if (str.equals(\"\")) {\r\n                return defaultValue;\r\n            }\r\n\r\n            try {\r\n                n = Integer.parseInt(str);\r\n                break;\r\n            } catch (NumberFormatException e) {\r\n                System.out.print(\"\u6570\u5b57\u8f93\u5165\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff1a\");\r\n            }\r\n        }\r\n        return n;\r\n    }\r\n\t\/**\r\n\t\u4ece\u952e\u76d8\u8bfb\u53d6\u4e00\u4e2a\u957f\u5ea6\u4e0d\u8d85\u8fc7limit\u7684\u5b57\u7b26\u4e32\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002\r\n\t*\/\r\n    public static String readString(int limit) {\r\n        return readKeyBoard(limit, false);\r\n    }\r\n\t\/**\r\n\t\u4ece\u952e\u76d8\u8bfb\u53d6\u4e00\u4e2a\u957f\u5ea6\u4e0d\u8d85\u8fc7limit\u7684\u5b57\u7b26\u4e32\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002\r\n\t\u5982\u679c\u7528\u6237\u4e0d\u8f93\u5165\u5b57\u7b26\u800c\u76f4\u63a5\u56de\u8f66\uff0c\u65b9\u6cd5\u5c06\u4ee5defaultValue \u4f5c\u4e3a\u8fd4\u56de\u503c\u3002\r\n\t*\/\r\n    public static String readString(int limit, String defaultValue) {\r\n        String str = readKeyBoard(limit, true);\r\n        return str.equals(\"\")? defaultValue : str;\r\n    }\r\n\t\/**\r\n\t\u7528\u4e8e\u786e\u8ba4\u9009\u62e9\u7684\u8f93\u5165\u3002\u8be5\u65b9\u6cd5\u4ece\u952e\u76d8\u8bfb\u53d6\u2018Y\u2019\u6216\u2019N\u2019\uff0c\u5e76\u5c06\u5176\u4f5c\u4e3a\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002\r\n\t*\/\r\n    public static char readConfirmSelection() {\r\n        char c;\r\n        for (; ; ) {\r\n            String str = readKeyBoard(1, false).toUpperCase();\r\n            c = str.charAt(0);\r\n            if (c == 'Y' || c == 'N') {\r\n                break;\r\n            } else {\r\n                System.out.print(\"\u9009\u62e9\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff1a\");\r\n            }\r\n        }\r\n        return c;\r\n    }\r\n\r\n    private static String readKeyBoard(int limit, boolean blankReturn) {\r\n        String line = \"\";\r\n\r\n        while (scanner.hasNextLine()) {\r\n            line = scanner.nextLine();\r\n            if (line.length() == 0) {\r\n                if (blankReturn) return line;\r\n                else continue;\r\n            }\r\n\r\n            if (line.length() &lt; 1 || line.length() > limit) {\r\n                System.out.print(\"\u8f93\u5165\u957f\u5ea6\uff08\u4e0d\u5927\u4e8e\" + limit + \"\uff09\u9519\u8bef\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165\uff1a\");\r\n                continue;\r\n            }\r\n            break;\r\n        }\r\n\r\n        return line;\r\n    }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[33],"tags":[46],"class_list":["post-681","post","type-post","status-publish","format-standard","hentry","category-java-","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/681"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=681"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/681\/revisions"}],"predecessor-version":[{"id":682,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/681\/revisions\/682"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}