目录

1.CMUtility工具类

2.客户类:Customer

3.客户信息管理类:CustomerList

4.CustomerView为主模块

二、程序的运行结果展示

1.添加客户

2.修改客户

3.删除客户

4.显示客户

5.退出

1.CMUtility工具类

提供系统的输入方法,输入的数据均满足要求即可实现功能

package com.ljj.p2.util;import java.util.*;
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;}
}

2.客户类:Customer

包含客户信息:客户姓名、性别、年龄、电话、邮箱

package com.ljj.p2.bean;public class Customer
{private String name;private char gender;private int age;private String phone;private String 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 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;}}

3.客户信息管理类:CustomerList

提供客户对象的数组以及客户对象的数量的属性total,还提供了将指定的客户添加到数组中,修改指定索引位置的客户信息,删除指定索引位置上的客户,获取所有的客户信息,获取指定索引位置上的客户,获取存储客户的数量等功能

package com.ljj.p2.service;import com.ljj.p2.bean.Customer;/*** *@Description CustomerList为Customer对象的管理模块*内部用数组管理一组Customer对象,并提供相应的添加、修改、删除*遍历方法。供CustomerView调用*@author ljj Email:2822819631@qq.com*@version*@date 2022年6月22日上午10:56:50**/
public class CustomerList
{private Customer[] customers;//用来保存客户对象的数组private int total = 0;//记录已保存的客户对象的数量/*** 用来初始化customers数组的构造器* @param totalCustomer:指定数组的长度*/public CustomerList(int totalCustomer){customers = new Customer[totalCustomer];}/*** *@Description 将指定的客户添加到数组中*@author ljj*@date 2022年6月22日下午12:10:54*@param customer*@return true:添加成功  false:添加失败*/public boolean addCustomer(Customer customer){if(total >= customers.length){return false;}customers[total] = customer;total++;return true;}/*** *@Description 修改指定索引位置的客户信息*@author ljj*@date 2022年6月22日下午12:16:26*@param index*@param cust*@return true:修改成功  false:修改失败*/public boolean replaceCustomer(int index,Customer cust){if(index <0 || index >= total){return false;}customers[index] = cust;return true; }/*** 删除指定索引位置上的客户*@Description*@author ljj*@date 2022年6月22日下午12:24:23*@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--;return true;}/*** *@Description 获取所有的客户信息*@author ljj*@date 2022年6月22日下午12:38:08*@return*/public Customer[] getAllCustomers(){Customer[] custs = new Customer[total];for(int i=0;i<total;i++){custs[i] = customers[i];}return custs;}/*** *@Description 获取指定索引位置上的客户*@author ljj*@date 2022年6月22日下午3:12:56*@param index*@return  如果找到了元素,则返回,如果没有找到在,则返回null。*/public Customer getCustomer(int index){if(index <0 || index >=total){return null;}return customers[index];}/*** *@Description 获取存储客户的数量*@author ljj*@date 2022年6月22日下午3:14:55*@return*/public int getTotal(){return total;}}

4.CustomerView为主模块

负责菜单的显示和处理用户操作

package com.ljj.p2.ui;import com.ljj.p2.bean.Customer;
import com.ljj.p2.service.CustomerList;
import com.ljj.p2.util.CMUtility;/*** *@Description CustomerView为主模块,负责菜单的显示和处理用户操作*@author ljj Email:2822819631@qq.com*@version*@date 2022年6月22日上午11:00:33**/
public class CustomerView
{private CustomerList customerList = new CustomerList(10);public CustomerView(){Customer customer = new Customer("xxs",'男',22,"12345677890","xxs@qq.com");customerList.addCustomer(customer);}/*** 显示《客户信息管理软件》的方法*@Description*@author ljj*@date 2022年6月22日下午3:24:04*/public void enterMainMenu(){boolean isFlag = true;while(isFlag){System.out.println("\n--------------客户信息管理软件-----------------");System.out.println("                 1. 添加客户");System.out.println("                 2. 修改客户");System.out.println("                 3. 删除客户");System.out.println("                 4. 客户列表");System.out.println("                 5. 退    出\n");System.out.print("                   请选择(1 - 5):");char menu = CMUtility.readMenuSelection();switch(menu){case'1':addNewCustomer();break;case'2':modifyCustomer();break;case'3':deleteCustomer();break;case'4':listAllCustomers();break;case'5':System.out.println("确认是否退出(Y/N):");char isExit = CMUtility.readConfirmSelection();if(isExit == 'Y'){isFlag = false;}}}}/*** 添加客户的操作*@Description*@author ljj*@date 2022年6月22日下午3:22:39*/private void addNewCustomer(){//System.out.println("添加客户操作");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();System.out.print("电话:");String phone = CMUtility.readString(15);System.out.print("邮箱:");String email = CMUtility.readString(30);//将上述数据封装到对象中Customer customer = new Customer(name,gender,age,phone,email);boolean isSuccess = customerList.addCustomer(customer);if(isSuccess){System.out.println("------------添加完成---------------");}else{System.out.println("---------客户目录已满,添加失败----------");}}/*** 修改客户的操作*@Description*@author ljj*@date 2022年6月22日下午3:22:55*/private void modifyCustomer(){//System.out.println("修改客户操作");System.out.println("--------------修改客户-------------");Customer cust;int number;for(;;){System.out.print("请选择待修改的客户编号(-1退出):");number = CMUtility.readInt();if(number == -1){return;}cust = customerList.getCustomer(number - 1);if(cust == null){System.out.println("无法找到指定客户!");}else{break;}}//修改客户信息System.out.print("姓名("+cust.getName()+"):");String name = CMUtility.readString(10, cust.getName());System.out.print("性别("+cust.getGender()+"):");char gender = CMUtility.readChar(cust.getGender());System.out.print("年龄("+cust.getAge()+"):");int age = CMUtility.readInt(cust.getAge());System.out.print("电话("+cust.getPhone()+"):");String phone = CMUtility.readString(15, cust.getPhone());System.out.print("邮S箱("+cust.getEmail()+"):");String email = CMUtility.readString(30, cust.getEmail());Customer newCust = new Customer(name, gender, age, phone, email);boolean isRepalaced = customerList.replaceCustomer(number-1, newCust);if(isRepalaced){System.out.println("--------------修改完成----------------");}else{System.out.println("--------------修改失败----------------");}}/*** 删除客户的操作*@Description*@author ljj*@date 2022年6月22日下午3:23:12*/private void deleteCustomer(){
//      System.out.println("删除客户操作");System.out.println("-------------- 删除客户---------------");int number;for(;;){System.out.print("请选择删除客户编号(-1退出):");number = CMUtility.readInt();if(number == -1){return ;}Customer customer = customerList.getCustomer(number-1);if(customer == null){System.out.println("无法找到指定客户!");}else{break;}}//找到了指定的客户System.out.print("确认是否删除(Y/N):");char isDelete = CMUtility.readConfirmSelection();if(isDelete == 'Y'){boolean deleteSuccess = customerList.deleteCustomer(number - 1);if(deleteSuccess){System.out.println("---------------删除完成--------------");}else{System.out.println("---------------删除失败--------------");}}else{return;}}/*** 显示客户列表的操作*@Description*@author ljj*@date 2022年6月22日下午3:23:25*/private 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<custs.length;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 customer1 =new CustomerView();customer1.enterMainMenu();}}

二、程序的运行结果展示

1.添加客户

2.修改客户

3.删除客户

4.显示客户

5.退出

Java项目二——客户信息管理软件相关推荐

  1. Java 简单控制台项目之客户信息管理软件 --- 凌宸1642

    项目二:客户信息管理软件 模拟实现一个基于文本界面的<客户信息管理软件> 进一步掌握编程技巧和调试技巧,熟悉面向对象编程 主要涉及以下知识点: 类结构的使用:属性.方法及构造器 对象的创建 ...

  2. 基于JAVA实现的客户信息管理软件(简易)

    文章目录 1.前期介绍 2.1 Customer类的设计 2.2 CustomerList类的设计 2.3 CustomerView类的设计 3.1 映入的CMUtitllity类 4. 结果显示 1 ...

  3. Java课程设计项目 客户信息管理软件 客户信息管理系统的实现

    public class CustomerView {                 //主函数                 public static void main(String[] a ...

  4. java se 学习之项目二:客户信息管理软件

    一.需求说明 模拟实现基于文本界面的<客户信息管理软件>. 该软件能够实现对客户对象的插入.修改和删除(用数组实现),并能够打印客户明细表. 项目采用分级菜单方式.主菜单如下: ----- ...

  5. Java小项目—客户信息管理软件(二)

    CustomerView类的设计 CustomerView为主模块,负责菜单的显示和处理用户操作. 本类封装以下信息: 创建最大包含10个客户对象的CustomerList对象,供以下各成员方法使用. ...

  6. Java基础项目——客户信息管理软件

    目录 前言 本项目目标 一.需求及软件设计结构说明 1.需求说明 1)主菜单 2)添加客户 3)修改客户 4)删除客户 5)客户列表 2.软件设计结构 1)Customer类的设计 2)Custome ...

  7. 零基础Java学习之初级项目实践(客户信息管理软件-附源码)

    项目涉及知识点 基础的面向对象编程项目. 类和对象(属性.方法及构造器) 类的封装 引用数组 数组的插入.删除和替换 对象的聚集处理 多对象协同工作 需求说明 总体说明 模拟实现基于文本界面的< ...

  8. Java项目二:客户信息管理系统(eclipse)

    文章目录 项目介绍 一.项目要求 1.添加客户 2.修改客户 3.删除客户 4.显示客户列表 二.软件设计结构 1.软件流程 2.CMUtility.java(实现键盘访问) 3.Customer.j ...

  9. Java学习路线:day11 客户信息管理软件

    文章目录 转载自atguigu.com视频 客户信息管理软件 需求说明书 软件设计结构 第1步:封装CMUtility工具类 第2步:Customer类的设计 第3步:CustomerList类的设计 ...

最新文章

  1. HarmonyOS 字体在自身控件中居中(使用text_alignment)
  2. 集成Lua到你的Android游戏(常见问题补充,解决,)
  3. 【Beta阶段】M2事后分析
  4. CentOS安装yum 镜像 举例阿里云镜像
  5. android小细节
  6. IntelliJ IDEA 创建 maven 创建java web 项目
  7. linux 学习笔记(基础)
  8. cad自动填写页码lisp_CAD图纸页码的自动生成-农夫也玩CAD
  9. 通过文献DOI下载外文文献
  10. 计算机声卡原理,来谈谈声卡的工作原理吧
  11. 广告数据定量分析:第一章——广告优化中的统计学
  12. 十九个国内外主流的三维GIS软件
  13. 【vue.js】+云存储(实现图片上传功能)
  14. Collecting Bugs (DP期望)
  15. 计算机网络 思科模拟器进行交换机端口隔离,跨交换机实现vlan实验
  16. HDU - 5514 Frogs
  17. Kubernetes dashboard搭建
  18. 《权威指南》笔记 -- 3.10 变量作用域
  19. Kaggle比赛之Artifical Neural Networks Applied to Taxi Destination Prediction代码整理
  20. CSS字体默认样式设置

热门文章

  1. ATmega8熔丝设置
  2. jasypt加密器的设置原理
  3. 求两个小数的“最小公倍数”
  4. Frontpage2003sp2使用教程
  5. 《微服务设计》 读书笔记
  6. 可转债券、质押式回购、买断式回购
  7. 每个人心里都有个非盈利性质的理想
  8. 今天玩了玩PSP上的战神,不愧是大作
  9. 基于Java毕业设计音乐管理系统源码+系统+mysql+lw文档+部署软件
  10. 让你的文章变得‘好看’--分享一些不错的字体颜色