客户信息管理系统
1.需求说明
模拟实现基于文本界面的<客户信息管理系统>
并实现以下功能:
-
最终功能展示:
- 添加客户:在控制台输入选项“1”,进入界面,实现添加。--------------------------------
- 查看客户列表--------------------------------------------------------------------
-修改客户信息-------------------------------------------------------
修改后查看客户列表-----------------------------------------------------------------------------------------------------------
删除客户-----------------------------------------------------------------------------------------------------------------------
2.所用知识点
(1)类结构的使用包括属性、方法以及构造器。
(2)对象的创建与使用方法。
(3)类的封装。
(4)ArrayList的使用
- 设计思路
(1)创建Customer类,设置客户对象属性,封装客户信息。
(2)创建CustomerList,CustomerList为Customer对象的管理模块,在其内部提供增删改除等方法,供CustomerView调用。
(3)创建CustomerView,负责菜单的显示和处理用户操作。
(4)此外,为了该系统的可用性操作性更高,还引用了定义的CMUtillity方法包。
3.完整代码:
=
!)
package Api.Test.work;
import java.util.Scanner;
public class CMUtility {
private static Scanner scanner = new Scanner(System.in);
/**
用于界面菜单的选择。该方法读取键盘,如果用户键入’1’-’5’中的任意字符,则方法返回。返回值为用户键入字符。
*/
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);
}
/**
从键盘读取一个字符,并将其作为方法的返回值。
如果用户不输入字符而直接回车,方法将以defaultValue 作为返回值。
*/
public static char readChar(char defaultValue) {
String str = readKeyBoard(1, true);
return (str.length() == 0) ? defaultValue : str.charAt(0);
}
/**
从键盘读取一个长度不超过2位的整数,并将其作为方法的返回值。
*/
public static int readInt() {
int n;
for (; ; ) {
String str = readKeyBoard(2, false);
try {
n = Integer.parseInt(str);
//integer 包装类
break;
} catch (NumberFormatException e) {
System.out.print("数字输入错误,请重新输入:");
}
}
return n;
}
/**
从键盘读取一个长度不超过2位的整数,并将其作为方法的返回值。
如果用户不输入字符而直接回车,方法将以defaultValue 作为返回值。
*/
public static int readInt(int defaultValue) {
int n;
for (; ; ) {
String str = readKeyBoard(2, true);
if (str.equals("")) {
return defaultValue;
}
try {
n = Integer