用博客记录我自学的点点滴滴
类图:
Customer类:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
public class Customer {
/**
* @name 客户姓名
* @sex 性别
* @age 年龄
* @phone 电话号码
* @email 邮箱
*/
private String name;
private String sex;
private int age;
private String phone;
private String email;
public Customer(){};
public Customer(String name,String sex, int age,String phone,String email){
this .name=name;
this .sex=sex;
this .age=age;
this .phone=phone;
this .email=email;
}
public String getName(){
return this .name;
}
public void setName(String name){
this .name=name;
}
public String getSex(){
return this .sex;
}
public void setSex(String sex){
this .sex=sex;
}
public String getPhone(){
return phone;
}
public void setPhone(String phone){
this .phone=phone;
}
public int getAge(){
return this .age;
}
public void setAge( int age){
this .age=age;
}
public String getEmail(){
return this .email;
}
public void setEmail(String email){
this .email=email;
}
}
|
CustomerList 类:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
public class CustomerList {
private Customer [] customers;
private static int total = 0 ;
/**
* 构造器初始化对象数组
* @param totalCustmoers 客户的总数
*/
public CustomerList( int totalCustmoers){
customers = new Customer[totalCustmoers];
}
/**
* 增加客户
* @param customer 客户
* @return 返回是否添加成功
*/
public boolean addCustomer(Customer customer){
if (customer!= null &&total<customers.length)
{customers[total]=customer;
total++;
return true ;}
else
{ return false ;}
}
/**
*替换
* @param index 指定的客户的编号
* @param cust 修改的客户
* @return 返回是否修改成功
*/
public boolean replaceCustomer( int index,Customer cust){
if (index>= 0 && index <total )
{
customers[index]=cust; return true ;
}
else
{
return false ;
}
}
/**
*删除客户
* @param index 指定的客户的编号
* @return 返回是否删除成功
*/
public boolean deleteCustomer( int index){
if (index<customers.length)
{
for ( int i=index;i<total- 1 ;i++)
{
customers[i]=customers[i+ 1 ]; /**把数据往前挪动*/
}
customers[total- 1 ]= null ;
total--; /**存储的数据的总数-1*/
return true ;
}
else
{
return false ;
}
}
/**
* 展现客户的信息
* @param index
* @return 返回客户
*/
public Customer getCustomer( int index){
if (index>= 0 && index<total)
{ return customers[index];}
else {
return null ;
}
}
/**
* 获取所有的客户
* @return 客户
*/
public Customer[] getAllCustomers(){
Customer [] cust = new Customer[total]; /**新建一个数组来接收原数组的数据*/
for ( int i= 0 ;i<total;i++){
cust[i]=customers[i];
}
return cust;
}
/**
* 得到客户的总数
* @return
*/
public int getTotal(){
return total;
}
}
|
CustomerVIew类:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
public class CustomerView {
private CustomerList customerList = new CustomerList( 10 );
/**
* 显示主菜单
*/
public void enterMainMenu(){
while ( true )
{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( "-----------------------------------------------------" );
Scanner input = new Scanner(System.in);
int op = input.nextInt();
switch (op)
{
case 1 : this .addNewCustomer(); break ;
case 2 : this .modifyCustomer(); break ;
case 3 : this .deleteCustomer(); break ;
case 4 : this .listAllCustomers(); break ;
case 5 :System.exit( 0 ); break ;
default :
System.out.println( "重新选择功能" ); break ;
}
}
}
/**
* 增加客户
*/
private void addNewCustomer(){
/**
* 从键盘处接收客户数据
*/
System.out.println( "-------------------添加客户-------------------" );
Scanner input = new Scanner(System.in);
System.out.println( "姓名:" );
String name = input.next();
System.out.println( "性别:" );
String sex=input.next();
System.out.println( "年龄:" );
int age = input.nextInt();
System.out.println( "电话号码:" );
String phone = input.next();
System.out.println( "电子邮箱:" );
String email = input.next();
/**
* 对客户数据进行封装
*/
Customer person = new Customer(name,sex,age,phone,email);
Boolean flag=customerList.addCustomer(person);
if (flag)
{
System.out.println( "-------------------添加成功-------------------" );
}
else
{
System.out.println( "-------------------添加失败-------------------" );
}
}
/**
* 修改客户信息
*/
private void modifyCustomer(){
System.out.println( "-------------------修改客户-------------------" );
System.out.println( "要修改的客户id:" );
Scanner input = new Scanner(System.in);
int number = input.nextInt();
Customer customer = customerList.getCustomer(number);
System.out.println( "姓名:" +customer.getName());
String name = CMUtility.readString( 5 ,customer.getName());
System.out.println( "性别:" +customer.getSex());
String sex = CMUtility.readString( 5 ,customer.getSex());
System.out.print( "年龄(" + customer.getAge() + "):" );
int age = CMUtility.readInt(customer.getAge());
System.out.print( "电话(" + customer.getPhone() + "):" );
String phone = CMUtility.readString( 13 , customer.getPhone());
System.out.print( "邮箱(" + customer.getEmail() + "):" );
String email = CMUtility.readString( 15 , customer.getEmail());
/**得到新的客户数据*/
customer = new Customer(name,sex,age,phone,email);
Boolean flag = customerList.replaceCustomer(number,customer);
if (flag)
{
System.out.println( "-------------------修改成功-------------------" );
}
else
{
System.out.println( "-------------------修改失败-------------------" );
}
}
/**
* 删除客户
*/
private void deleteCustomer(){
System.out.println( "-------------------删除客户-------------------" );
System.out.println( "要删除的客户id:" );
Scanner input = new Scanner(System.in);
int number = input.nextInt();
while ( true ){
System.out.println( "退出(-1)" );
if (number>= 0 && number<customerList.getTotal())
{
System.out.println( "找到指定客户" );
}
else if (number==- 1 )
{
return ;
}
else
{
System.out.println( "输入错误" ); break ;
}}
System.out.println( "是否确认删除该客户?Y/N" );
String ch = input.next();
char o = ch.charAt( 0 );
if (o== 'Y' )
{
boolean flag = customerList.deleteCustomer(number);
if (flag){
System.out.println( "-------------------删除成功-------------------" );
}
else
{
System.out.println( "-------------------删除失败-------------------" );
}
}
else {
return ;
}
}
/**
* 获取客户列表
*/
private void listAllCustomers(){
Customer [] customer=customerList.getAllCustomers();
if (customer.length== 0 )
{
System.out.println( "没有任何客户数据" );
}
else {
for ( int i= 0 ;i< customer.length;i++)
{
System.out.println( "姓名:" +customer[i].getName()+ "\\t" + "性别" +customer[i].getSex()+ "\\t" + "年龄:" +customer[i].getAge()+ "\\t" + "电话号码:" +customer[i].getPhone()+ "\\t" + "电子邮箱:" +customer[i].getEmail()+ "\\t" );
}
}}
public static void main(String[] args) {
CustomerView co = new CustomerView();
co.enterMainMenu();
}
}
|
工具类:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
public class CMUtility {
private static Scanner scanner = new Scanner(System.in);
public static String readString( int limit) {
return readKeyBoard(limit, false );
}
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;
}
|
总结
到此这篇关于利用java实现一个客户信息管理系统的文章就介绍到这了,更多相关java客户信息管理系统内容请搜索快网idc以前的文章或继续浏览下面的相关文章希望大家以后多多支持快网idc!
原文链接:https://blog.csdn.net/qq_52062446/article/details/115585334
相关文章
猜你喜欢
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
- 64M VPS建站:是否适合初学者操作和管理? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-25 48
-
2025-05-29 80
-
2025-05-25 59
-
2025-05-25 29
-
2025-05-29 54
热门评论