需求说明:
模拟实现基于文本界面的《客户信息管理软件》。 该软件能够实现对客户对象的插入、修改和删除(用数组实现),并能够打印客户明细表。 项目采用分级菜单方式。主菜单如下:
-----------------客户信息管理软件-----------------
1 添 加 客 户
2 修 改 客 户
3 删 除 客 户
4 客 户 列 表
5 退 出
请选择(1-5):_
每个客户的信息被保存在Customer对象中。 以一个Customer类型的数组来记录当前所有的客户。 每次“添加客户”(菜单1)后,客户(Customer)对象被添加到数组中。 每次“修改客户”(菜单2)后,修改后的客户(Customer)对象替换数组中原对象。 每次“删除客户”(菜单3)后,客户(Customer)对象被从数组中清除。 执行“客户列表 ”(菜单4)时,将列出数组中所有客户的信息。
“添加客户”的界面及操作过程如下所示:
请选择(1-5):
-------------------添加客户--------------
姓名:佟刚
性别:男
年龄:35
电话:010-56253825
邮箱:tongtong@atguigu.com
---------------------添加完成------------
键盘访问的实现:
项目中提供了CMUtility.java类,可用来方便地实现键盘访问。 该类提供了以下静态方法: public static char readMenuSelection() 用途:该方法读取键盘,如果用户键入’1’-’5’中的任意字符,则方法返回。返回值为用户键入字符。 public static char readChar() 和 public static char readChar(char defaultValue) 用途:这两个方法功能相同,均从键盘读取一个字符,并将其作为方法的返回值。
参数: defaultValue — 如果用户不输入字符而直接回车,方法将以defaultValue 作为返回值。(提示:此方法可在修改客户时调用)
public static int readInt() 和public static int readInt(int defaultValue) 用途:这两个方法功能相同,均从键盘读取一个长度不超过2位的 整数,并将其作为方法的返回值。 参数: defaultValue — 如果用户不输入字符而直接回车,方法将以defaultValue 作为返回值。 public static String readString(int limit) 和 public static String readString(int limit, String defaultValue) 用途:这两个方法功能相同,均从键盘读取一个长度不超过limit的字符串,并将其作为方法的返回值。 参数:limit — 指定字符串的最大长度 defaultValue — 如果用户不输入字符而直接回车,方法将以defaultValue 作为返回值。 public static char readConfirmSelection() 用途:从键盘读取‘Y’或’N’,并将其作为方法的返回值。
第1步 — Customer类的设计
Customer为实体类,用来封装客户信息 该类封装客户的以下信息: String name :客户姓名 char gender :性别 int age :年龄 String phone:电话号码 String email :电子邮箱 提供各属性的get/set方法 提供所需的构造器(可自行确定)按照设计要求编写Customer类,并编译 在Customer 类中临时添加一个main方法中,作为单元测试方法。 在方法中创建Customer对象,并调用对象的各个方法,以测试该类是否编写正确。
第2步 — CustomerList类的设计:
CustomerList为Customer对象的管理模块,内部使用数组管理一组Customer对象 本类封装以下信息: Customer[] customers:用来保存客户对象的数组 int total = 0 :记录已保存客户对象的数量 该类至少提供以下构造器和方法: public CustomerList(int totalCustomer) 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()
public CustomerList(int totalCustomer) 用途:构造器,用来初始化customers数组 参数:totalCustomer:指定customers数组的最大空间 public boolean addCustomer(Customer customer) 用途:将参数customer添加组中最后一个客户对象记录之后 参数:customer指定要添加的客户对象 返回:添加成功返回true;false表示数组已满&#x