客户信息管理系统(java)

  • 一、系统需要的类
    • 1、工具类:CMUtility
    • 2、客户类:Customer
    • 3、客户信息管理类:CustomerList
    • 4、客户信息展示类:CustomerList
  • 二、类的具体实现
    • 1、工具类:CMUtility
    • 2、客户类:Customer
    • 3、客户信息管理类:CustomerList
    • 4、客户信息展示类:CustomerList

一、系统需要的类

1、工具类:CMUtility

为系统提供输入方法,所有的数据输入均需要进行数据校验。

2、客户类:Customer

包含数据成员:客户姓名,性别,年龄,电话号码,电子邮箱等信息,以及构造器和get、set方法。

3、客户信息管理类:CustomerList

<1>成员:
➀客户对象数组:用于储存客户对象
➁整型变量total:用于记录已保存的客户数量
<2> 功能:
提供基本的构造器,get、set方法。实现对对象数组中的客户对象进行增删改查,索引定位获取所有已保存的客户对象等功能。

4、客户信息展示类:CustomerList

<1>成员:客户信息管理类的实例化对象
<2>功能:系统主界面显示、对客户对象的各项指标增删改查的具体实现

二、类的具体实现

1、工具类:CMUtility

package hu2;
import java.util.Locale;
import java.util.Scanner;
public class CMUtility {private static Scanner sc = new Scanner(System.in);/*** 输入y/n,用于确认操作是否执行* @return Y获取N(小写的y或者n经过处理变成了大写)*/public static char readConfirm() {char c = '0';while (true) {String str = readKeyBoard(1, false);c = str.toUpperCase(Locale.ROOT).charAt(0);if ( c == 'Y' || c == 'N') {break;} else {System.out.println("输入有误(y/n),请重新输入:");}}return c;}/*** 从键盘读入一个字符,用于菜单选择* @return 返回一个字符*/public static char readSelection() {char c;while (true) {String str = readKeyBoard(1, false);c = str.charAt(0);if ( c != '1' && c != '2' && c != '3' && c != '4' && c != '5' ) {System.out.println("输入有误(1--5),请重新输入:");} else {break;}}return c;}/*** 从键盘读入最大长度为limit的字符串* 如果直接回车则返回defaultValue,否则返回从键盘读入的字符串* @param limit 最大长度限制* @param defaultValue 默认值* @return 返回字符串*/public static String readString(int limit, String defaultValue ) {String str = readKeyBoard(limit, true);if ( str.equals("") ) {return defaultValue;}return str;}/*** 如果直接回车则返回default,否则从键盘读入一个字符* @param defaultValue* @return*/public static char readChar( char defaultValue ) {String str = readKeyBoard(1, true);if ( str.equals("") ) {return defaultValue;}char c = str.charAt(0);return c;}/*** 如果直接回车,则返回defaultValue,否则最大输入长度限制为limit* @param limit 长度限制* @param defaultValue 默认值,如果直接回车,则返回该值* @return*/public static int readInt(int limit, int defaultValue ) {int ans = 0;while (true) {String str = readKeyBoard(limit, true);if ( str.equals("") ) {return defaultValue;}try {ans = Integer.parseInt(str);break;} catch (NumberFormatException e ) {System.out.println("数字输入错误,请重新输入:");}}return ans;}/*** 从键盘读取最大长度为limit的整数* 用于读入【年龄】* @param limit 最大长度限制* @return*/public static int readInt(int limit) {int ans = 0;while (true) {String str = readKeyBoard(limit, false);try {ans = Integer.parseInt(str);break;} catch (NumberFormatException e ) {System.out.println("数字输入错误,请重新输入:");}}return ans;}/*** 从键盘读入一个字符* 用于输入【性别】* @return*/public static char readChar() {String str = readKeyBoard(1, false);char c = str.charAt(0);return c;}/***从键盘读入最大长度为limit的字符串* 用于输入【电话号码,邮箱,姓名】* @param limit 从键盘读入的最大字符串长限制* @return 返回字符串*/public static String readString(int limit ) {return readKeyBoard(limit, false);}/*** 私有方法,供本类中其他方法调用,不对外暴露* 用于从键盘读入长度不超过limit的字符串,value表示是否需要在输入为空时返回空字符串* @param limit 待输入的字符串长度最大限制* @param value 是否需要在输入为空时返回空字符串* @return 返回字符串*/private static String readKeyBoard( int limit, boolean value ) {String line = "";while (sc.hasNextLine()) {line = sc.nextLine();if ( line.equals("")) {if (value) {return line;}}if ( line.length() < 1 || line.length() > limit ) {System.out.println("输入错误(不超过" + limit + "个字符),请重新输入:");} else {break;}}return line;}
}

2、客户类:Customer

package hu2;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;}
}

3、客户信息管理类:CustomerList

package hu2;public class CustomerList {private Customer[] customers; //客户数组private int total = 0; //记录已保存的客户数/*** 获取所有客户信息* @return*/public Customer[] getAllCustomer() {Customer[] custs = new Customer[total];for ( int i=0; i<total; ++i ) {custs[i] = customers[i];}return custs;}/*** 修改指定位置的客户* @param index 索引值* @param cust 修改后的客户* @return*/public boolean modifyCustomer( int index, Customer cust ) {if ( index < 0 || index >= total ) {return false;}customers[index] = cust;return true;}/*** 删除指定索引位置客户,删除成功返回true,否则返回false* @param index 索引值* @return*/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] = null;return true;}/*** 添加客户到客户数组* @param cust 待添加的客户* @return 返回值表示是否添加成功*/public boolean addCustomer( Customer cust ) {if ( total >= customers.length ) {return false;}customers[total++] = cust;return true;}/*** 获取指定索引位置的客户,如果索引不在指定范围则返回null,* 否则返回该索引对应的客户* @param index* @return*/public Customer getIndexCustomer( int index ) {if ( index < 0 || index >= total ) {return null;}return customers[index];}/*** 构造器,为对象数组开辟空间* @param totalCustomer*/public CustomerList( int totalCustomer ) {customers = new Customer[totalCustomer];}public CustomerList() {}public CustomerList(Customer[] customers, int total) {this.customers = customers;this.total = total;}public Customer[] getCustomers() {return customers;}public void setCustomers(Customer[] customers) {this.customers = customers;}public int getTotal() {return total;}public void setTotal(int total) {this.total = total;}
}

4、客户信息展示类:CustomerList

package hu2;public class CustomerView {private CustomerList customerList = new CustomerList(2000);/*** 修改客户信息,如果回车则该项不修改,否则该项信息修改为输入后的信息*/public void modifyCustomer() {System.out.println("请输入待修改客户的编号(-1退出):");int num = CMUtility.readInt(4);if ( num == -1 ) {return;}if ( (num <= 0 && num != -1) || num > customerList.getTotal() ) {System.out.println("无法找到指定客户!");return;}Customer indexCustomer = customerList.getIndexCustomer( num -  1 );if ( indexCustomer == null ) {System.out.println("无法找到指定客户!");return;}//找到了指定客户System.out.print("姓名(" + indexCustomer.getName() + "):");String name = CMUtility.readString(5, indexCustomer.getName());System.out.print("性别(" + indexCustomer.getGender() + "):");char gender = CMUtility.readChar(indexCustomer.getGender());System.out.print("年龄(" + indexCustomer.getAge() + "):");int age = CMUtility.readInt(3, indexCustomer.getAge());System.out.print("电话号码(" + indexCustomer.getPhone() + "):");String phone = CMUtility.readString(11, indexCustomer.getPhone());System.out.print("邮箱(" + indexCustomer.getEmail() + "):");String email = CMUtility.readString(32, indexCustomer.getEmail());boolean isModifySuccess = customerList.modifyCustomer(num - 1, new Customer(name, gender, age, phone, email));if ( isModifySuccess ) {System.out.println("----------------------修改成功!-------------------------");} else {System.out.println("--------------------修改失败!----------------------------");}}/*** 删除客户*/public void deleteCustomer() {int ans;Customer indexCustomer;while (true) {System.out.println("请输入您要删除客户的编号(-1退出):");ans = CMUtility.readInt(3);if ( ans == -1 ) {return;}indexCustomer = customerList.getIndexCustomer(ans-1);if ( indexCustomer == null ) {System.out.println("无法找到指定客户!");return;} else {break;}}//找到了指定用户System.out.println("-------");System.out.println("姓名(" + indexCustomer.getName() + ")");System.out.println("性别(" + indexCustomer.getGender() + ")");System.out.println("年龄(" + indexCustomer.getAge() + ")");System.out.println("电话号码(" + indexCustomer.getPhone() +")");System.out.println("邮箱(" + indexCustomer.getEmail() + ")");System.out.println("-------");System.out.println("是否确认删除(Y/N):");char isExit = CMUtility.readConfirm();if ( isExit == 'N') {return;}boolean isDeleteSuccess = customerList.deleteCustomer(ans-1);if ( isDeleteSuccess == false ) {System.out.println("---------------删除失败!-------------------");return;} else {System.out.println("-------------删除成功!--------------------");}}/*** 客户列表,显示所有客户信息*/public void listAllCustomers() {int flag = 1;System.out.println("编号\t姓名\t性别\t年龄\t电话号码\t\t电子邮箱");Customer[] allCustomer = customerList.getAllCustomer();for ( Customer cust : allCustomer ) {System.out.println((flag++) + "\t" + cust.getName() + "\t" + cust.getGender() + "\t" +cust.getAge() + "\t" + cust.getPhone() + "\t" + cust.getEmail());}}/*** 添加客户*/public void addCustomer() {System.out.println("---------------添加客户-------------------");System.out.print("请输入姓名:");String name = CMUtility.readString(10);System.out.print("请输入性别:");char gender = CMUtility.readChar();System.out.print("请输入年龄:");int age = CMUtility.readInt(3);System.out.print("请输入电话号码:");String phone = CMUtility.readString(11);System.out.print("请输入邮箱:");String email = CMUtility.readString(30);Customer cust = new Customer(name, gender, age, phone, email);boolean isAddSuccess = customerList.addCustomer(cust);if ( isAddSuccess ) {System.out.println("---------------添加成功!-------------------");} else {System.out.println("---------------添加失败!--------------------");}}/*** 《客户信息管理软件》系统主界面*/public void enterMainMenu() {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("                  请输入您的选择(1--5):");char selection = CMUtility.readSelection();switch (selection) {case '1':
//                    System.out.println("添加客户");addCustomer();break;case '2':
//                    System.out.println("删除客户");deleteCustomer();break;case '3':
//                    System.out.println("修改客户");modifyCustomer();break;case '4':
//                    System.out.println("客户列表");listAllCustomers();break;case '5':
//                    System.out.println("退出");break;}}}public static void main(String[] args) {CustomerView custView = new CustomerView();custView.enterMainMenu();}
}

客户信息管理系统(java)相关推荐

  1. 客户信息管理系统——Java

    客户信息管理系统--Java 该系统没有涉及文件及数据库,适合刚接触java的新手进行练习.模拟实现基于文本界面的客户软件管理系统.能够实现基本增删改查操作以及类的使用 文件排布如下图: 源代码 Cu ...

  2. 掌财社:Java项目案例之客户信息管理系统的实现

    本篇文章将使用所学过的Java知识来实现一个简单的客户信息管理系统的小项目,下面内容是具体地实现过程,这篇文章供大家参考学习,希望能帮助到大家. 类图: Customer类: public class ...

  3. java客户信息管理系统_JavaWeb客户信息管理系统.doc

    JavaWeb客户信息管理系统 xxxx 信息科学与工程学院 课程设计 题 目: 客户信息管理系统 姓 名: xxxx 学 号: xxxx 班 级: xxxx 课 程: Java Web 任课教师 x ...

  4. java计算机毕业设计房产客户信息管理系统源码+系统+lw文档+mysql数据库+部署

    java计算机毕业设计房产客户信息管理系统源码+系统+lw文档+mysql数据库+部署 java计算机毕业设计房产客户信息管理系统源码+系统+lw文档+mysql数据库+部署 本源码技术栈: 项目架构 ...

  5. java毕业生设计房产客户信息管理系统计算机源码+系统+mysql+调试部署+lw

    java毕业生设计房产客户信息管理系统计算机源码+系统+mysql+调试部署+lw java毕业生设计房产客户信息管理系统计算机源码+系统+mysql+调试部署+lw 本源码技术栈: 项目架构:B/S ...

  6. 【附源码】计算机毕业设计JAVA房产客户信息管理系统

    [附源码]计算机毕业设计JAVA房产客户信息管理系统[附源码] 目运行 环境项配置: Jdk1.8 + Tomcat8.5 + Mysql + HBuilderX(Webstorm也行)+ Eclis ...

  7. java毕业设计企业客户信息管理系统mybatis+源码+调试部署+系统+数据库+lw

    java毕业设计企业客户信息管理系统mybatis+源码+调试部署+系统+数据库+lw java毕业设计企业客户信息管理系统mybatis+源码+调试部署+系统+数据库+lw 本源码技术栈: 项目架构 ...

  8. CRM客户信息管理系统

    一.项目简介 客户信息管理系统,基于SSM实现的客户信息管理系统.演示视频请点击[演示视频] 二.技术实现 后台框架:Spring.SpringMVC.MyBatis UI界面:JSP.jQuery ...

  9. (附源码)springboot客户信息管理系统 毕业设计 181936

    基于springboot的anjuleanjule客户信息管理系统 摘 要 本论文主要论述了如何使用Java语言开发一个anjule客户信息管理系统,本系统将严格按照软件开发流程进行各个阶段的工作,采 ...

  10. (附源码)anjule客户信息管理系统 毕业设计 181936

    摘 要 本论文主要论述了如何使用Java语言开发一个anjule客户信息管理系统,本系统将严格按照软件开发流程进行各个阶段的工作,采用B/S架构,Springboot框架进行开发.在引言中,作者将论述 ...

最新文章

  1. Single Image Dehazing via Conditional Generative Adversarial Network(CVPR2018-图像去雾)
  2. Java 程序员都该懂的 HashMap
  3. 深入理解JVM虚拟机(三):虚拟机性能监控工具
  4. Python SqlAlchemy使用方法
  5. 下载的VS2017工程编译出错的问题
  6. PB代码动态解析执行器
  7. python函数的嵌套调用_python函数的嵌套调用
  8. 2d 蓝图_“二渲三”打破传统思维!Netflix冲奥动画会推动2D动画变革吗?
  9. 什么是复制和交换习语?
  10. react引入本地mp4视频
  11. 查看计算机温度指令,怎么看cpu温度(电脑CPU温度怎么查看?)
  12. 几个项目管理经典小故事,发人深思
  13. php larval 数据库when,Laravel DB类操作数据库
  14. 个人网站博客完美添加谷歌广告增加收入详细步骤
  15. 分数统计设计java程序_(windows综合程序)设计一个学生平时成绩统计软件 最后的Java作业...
  16. ViTAE论文阅读与官方代码讲解
  17. Redhat7 yum安装有问题+yum无法使用+There are no enabled repos. Run “yum repolist all“ to see the repos you ha
  18. 终止正在运行的ORACLE作业
  19. 火爆业界的明星,下一代存储技术的先行: NVDIMM 你了解吗?
  20. 【收集】键盘钢琴 和弦琴谱 (带HTML版开发流程)

热门文章

  1. 第二章 ARM体系结构与指令集——ARM
  2. Worktile、Teambition与Tower项目管理软件对比
  3. Web 实现登录记住密码功能
  4. 推荐一个在线视频学习、在线试题练习、在线同步考试开源系统
  5. linux免费私人云盘软件,Appnode+kodexplorer免费搭建私有云盘
  6. 在Ubuntu22.04中安装微信、QQ
  7. quartz 定时任务 表达式
  8. c语言最新标准c22,C++20标准(c++标准手册) 官方最新版PDF
  9. Laravel下载文件及文档
  10. PCA人脸识别详解——初学者必看