客户信息管理系统
技能点:
- 类结构的使用:属性、方法及构造器
- 对象的创建与使用
- 类的封装性
- 声明和使用数组
- 数组的插入、删除和替换
- 关键字的使用:this
需求说明:
该软件能够实现对客户对象的插入、修改和删除(用数组实现),并能够打印客户明细表。
菜单:
功能一:
功能二:
功能三:
功能四:
框架搭建:
1 | 菜单面板 |
代码实现:
Main类:
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
65package view_ui;
/**
* @项目名称:Customer_Information_management_System
* @包名称:view_ui
* @类名称:Main
* @类描述:Main方法,搭建起主要框架
* @创建人:青春玩命的年代
* @创建时间:2021年10月26日
* @版本:
*/
import model_bean.*;
import controller_service.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
SqList.InitList();
boolean flag = true;
int selection;
System.out.println("--------------客户信息管理软件--------------");
System.out.println("");
System.out.println("\t\t1 添 加 客 户");
System.out.println("\t\t2 修 改 客 户");
System.out.println("\t\t3 删 除 客 户");
System.out.println("\t\t4 客 户 列 表");
System.out.println("\t\t5 退 出");
System.out.println("");
while(flag) {
System.out.println("\t\t ......");
System.out.print("\t\t请选择(1-5):");
//获取用户选择
selection = scan.nextInt();
//输入保护机制
selection = Utility.Protected(selection);
//选择模块
switch(selection) {
case 1:
//功能1
Utility.Insert();
break;
case 2:
//功能2
Utility.Change();
break;
case 3:
//功能3
Utility.Delet();
break;
case 4:
//功能4
Utility.Print();
break;
case 5:
//功能5
Utility.Exite(flag);
break;
}
}
scan.close();
}
}Utility工具类:
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
110package controller_service;
/**
* @项目名称:Customer_Information_management_System
* @包名称:controller_service
* @类名称:Utility
* @类描述:工具类,封装了一些Main方法中调用的方法
* @创建人:青春玩命的年代
* @创建时间:2021年10月26日
* @版本:
*/
import java.util.Scanner;
import model_bean.*;
public class Utility {
static Scanner scan = new Scanner(System.in);
//声明常用变量
static int num, age;
static String name, sex, tel, email;
//输入保护机制
public static int Protected(int selection) {
if(selection >= 1 && selection <= 5)
return selection;
else {
int e = 0;
boolean flag = true;
while(flag) {
System.out.print("\t\t请重新选择:");
e = scan.nextInt();
if(e >= 1 && e <= 5)
flag = false;
}
return e;
}
}
//添加客户
public static void Insert() {
System.out.println("------------------添加客户------------------");
System.out.print("姓名:");
name = scan.next();
System.out.print("性别:");
sex = scan.next();
System.out.print("年龄:");
age = scan.nextInt();
System.out.print("电话:");
tel = scan.next();
System.out.print("邮箱:");
email = scan.next();
SqList.Insert(name, sex, age, tel, email);
System.out.println("------------------添加完成------------------");
}
//修改客户
public static void Change() {
System.out.println("------------------修改客户------------------");
System.out.print("请选择待修改客户的编号(-1退出):");
num = scan.nextInt();
if(num == -1)
return;
System.out.print("姓名" + "(" + SqList.getCustomers(num).getName() + "):");
name = scan.next();
System.out.print("性别" + "(" + SqList.getCustomers(num).getSex() + "):");
sex = scan.next();
System.out.print("年龄" + "(" + SqList.getCustomers(num).getAge() + "):");
age = scan.nextInt();
System.out.print("电话" + "(" + SqList.getCustomers(num).getTel() + "):");
tel = scan.next();
System.out.print("邮箱" + "(" + SqList.getCustomers(num).getEmail() + "):");
email = scan.next();
SqList.Change(num, name, sex, age, tel, email);
System.out.println("------------------修改完成------------------");
}
//删除客户
public static void Delet() {
System.out.println("------------------删除客户------------------");
System.out.print("请选择待删除客户的编号(-1退出):");
num = scan.nextInt();
if(num == -1)
return;
System.out.print("确认是否删除(Y/N):");
String flag = scan.next();
if(flag == "Y") {
SqList.Delet(num);
System.out.println("------------------删除完成------------------");
}else
System.out.println("------------------删除中止------------------");
}
//输出客户列表
public static void Print() {
System.out.println("------------------客户列表------------------");
System.out.println("编号 姓名 性别 年龄 电话\t\t邮箱");
SqList.Print();
System.out.println("------------------列表完成------------------");
}
//退出
public static void Exite(boolean flag) {
System.out.println("------------------退 出------------------");
System.out.println("确认是否删除(Y/N):");
String flags = scan.next();
if(flags == "Y") {
flag = false;
System.out.println("------------------退出成功------------------");
}else
System.out.println("------------------退出中止------------------");
System.out.println("------------------退出成功------------------");
}
}SqList类:
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
62package model_bean;
/**
* @项目名称:Customer_Information_management_System
* @包名称:model_bean
* @类名称:SqList
* @类描述:线性表类,封装了线性表的属性和需要的基本方法
* @创建人:青春玩命的年代
* @创建时间:2021年10月28日
* @版本:
*/
public class SqList {
//属性:
final int MAXSIZE = 20;
private static Customer[] customer = new Customer[20];
private static int length = 0;
//方法:
//初始化线性表
public static void InitList() {
for(int i = 0; i < 20; i ++) {
customer[i] = new Customer();
}
length = 0;
}
//插入新的对象
public static void Insert(String name, String sex, int age, String tel, String email) {
customer[length].setName(name);
customer[length].setSex(sex);
customer[length].setAge(age);
customer[length].setTel(tel);
customer[length].setEmail(email);
length ++;
}
//调用数组
public static Customer getCustomers(int num) {
return customer[num];
}
//修改某个数组的数据
public static void Change(int num, String name, String sex, int age, String tel, String email) {
num = num - 1;
customer[num].setName(name);
customer[num].setSex(sex);
customer[num].setAge(age);
customer[num].setTel(tel);
customer[num].setEmail(email);
}
//删除某个元素
public static void Delet(int num) {
//删除第i个元素,并将后面的元素前移
for(int k = num; k < length; k++)
{
customer[k-1] = customer[k];
}
length ++;
}
//输出线性表
public static void Print() {
for(int i = 0; i < length; i ++) {
System.out.println((i + 1) + " " + customer[i].getName() + " " + customer[i].getSex() + " " + customer[i].getAge() + " " + customer[i].getTel() + "\t" + customer[i].getEmail());
}
}
}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
53
54
55
56
57
58package model_bean;
/**
* @项目名称:Customer_Information_management_System
* @包名称:model_bean
* @类名称:Customer
* @类描述:客户类,用来辅助构成线性表结构
* @创建人:青春玩命的年代
* @创建时间:2021年10月28日
* @版本:
*/
public class Customer {
//属性:
private String name, sex, tel, email;
private int age;
//构造器:
Customer(){
}
public Customer(String name, String sex, int age, String tel, String email){
this.name = name;
this.sex = sex;
this.age = age;
this.tel = tel;
this.email = email;
}
//方法:
public String getName() {
return this.name;
}
public String getSex() {
return this.sex;
}
public String getEmail() {
return this.email;
}
public String getTel() {
return this.tel;
}
public int getAge() {
return this.age;
}
public void setName(String name) {
this.name = name;
}
public void setSex(String sex) {
this.sex = sex;
}
public void setEmail(String email) {
this.email = email;
}
public void setTel(String tel) {
this.tel = tel;
}
public void setAge(int age) {
this.age = age;
}
}
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 青春玩命的年代!
评论