文章目录
- 一.开发流程
- 二.需求分析
- 三.设计
- 3.2 分层设计
- 3.3 bean
- 3.4 View
- 功能说明
- 思路分析
- code实现
- 3.5 App
- 3.6 Service
- 显示客户列表
- 添加客户
- 删除客户
一.开发流程
二.需求分析
主界面
复制代码
1
2
3
4
5
6
7
8
9
10
11---------------------------客户信息管理软件----------------- 1 添 加 客 户 2 修 改 客 户 3 删 除 客 户 4 客 户 列 表 5 退 出 请选择(1-5):_
添加客户
复制代码
1
2
3
4
5
6
7
8
9
10
11请选择(1-5):1 ---------------------添加客户--------------------- 姓名:张三 性别:男 年龄:30 电话:010-56253825 邮箱:zhang@abc.com ---------------------添加完成---------------------
删除客户
复制代码
1
2
3
4
5
6
7
8请选择(1-5):3 ---------------------删除客户--------------------- 请选择待删除客户编号(-1退出):1 确认是否删除(Y/N):y ---------------------删除完成---------------------
客户列表
复制代码
1
2
3
4
5
6
7
8
9请选择(1-5):4 ---------------------------客户列表--------------------------- 编号 姓名 性别 年龄 电话 邮箱 1 张三 男 30 010-56253825 abc@email.com 2 李四 女 23 010-56253825 lisi@ibm.com 3 王芳 女 26 010-56253825 wang@163.com -------------------------客户列表完成-------------------------
该软件scala能够实现对客户对象的插入、修改和删除,显示,查询(用ArrayBuffer或者ListBuffer实现),并能够打印客户明细表。
三.设计
3.2 分层设计
一共分四层
3.3 bean
- 先分析Cusotmer有哪些属性
复制代码
1
2
3
4
5
6
7
8//属性 var id:Int = _ var name:String = _ var gender:Char = _ var ger:Short = _ var tel:String = _ var email:String = _
- 构造器
复制代码
1
2
3
4
5
6
7
8
9
10
11//辅助构造器 def this(id:Int,name:String,gender:Char,age:Short,tel:String,email:String){ this this.id = id this.name = name this.gender = gender this.age = age this.tel = tel this.email = email }
3.4 View
本来是应该先写Service层
但是鉴于此场景,应该先写一个简单的View
功能说明
显示主菜单 & 完成退出
复制代码
1
2
3
4
5
6
7
8
9
10
11---------------------------客户信息管理软件--------------------------- 1 添 加 客 户 2 修 改 客 户 3 删 除 客 户 4 客 户 列 表 5 退 出 请选择(1-5):_
思路分析
1.主菜单显示放到while
2.用户输入选择
3.输入5退出
code实现
复制代码
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
38package Customer.view import scala.io.StdIn class CustomerView { //定义变量 控制退出循环while var loop = true //接收用户输入 var key = ' ' def mianMenu() = { do{ println("--------------------------客户信息管理软件---------------------------") println(" 1 添 加 客 户") println(" 2 修 改 客 户") println(" 3 删 除 客 户") println(" 4 客 户 列 表") println(" 5 退 出") println(" 请选择(1-5):_") //key 来接收用户输入 key = StdIn.readChar() //key match 匹配 key match { case '1' => println("添 加 客 户") case '2' => println("修 改 客 户") case '3' => println("删 除 客 户") case '4' => println("客 户 列 表") case '5' => this.loop = false } }while(loop) } }
3.5 App
调用全部接口
3.6 Service
显示客户列表
主菜单接收一个4 ,打印出来客户列表
调用Service的 list 方法
1.编写一个方法 ,返回当前系统有哪些客户
2.客户放在哪里? 内存----> 可变集合 ----> ArrayBuffer
bean.customer
复制代码
1
2
3
4
5
6// 重写了toString方法 override def toString: String = { this.id + "tt" + this.name + this.gender + "tt" + this.age + this.tel + "tt" + this.email }
CustomerService
复制代码
1
2
3
4
5
6
7
8
9
10class CustomerService { //customer是存放客户的,先初始化一个 为了测试 val customers = ArrayBuffer(new Customer(1,"Tom",'男',10,"120","120@qq.com")) def list() = { this.customers } }
View.customerView
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18def list() = { println() println("---------------------------客户列表---------------------------") println("编号tt姓名tt性别tt年龄tt电话tt邮箱") //for 遍历 //1 获取到CustomerSerivce 的 customers ArrayBuffer val customers = customerService.list() for(customer <- customers){ //重写customer的toString ,返回信息(格式化) println(customer) } println("---------------------------客户列表完成---------------------------") println() }
添加客户
bean.customer
复制代码
1
2
3
4
5
6
7
8
9
10//第二个构造器,方便id设置 def this(name:String,gender:Char,age:Short,tel:String,email:String){ this this.name = name this.gender = gender this.age = age this.tel = tel this.email = email }
Service
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13//添加客户 def add(customer: Customer) = { //设置ID customerNum += 1 customer.id = customerNum //添加到customers customers.append(customer) true }
view
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23// 添加客户 def add() = { println() println("---------------------------添加客户---------------------------") println("姓名:") val name = StdIn.readLine() println("性别:") val gender = StdIn.readChar() println("年龄:") val age = StdIn.readShort() println("电话:") val tel = StdIn.readLine() println("邮箱:") val email = StdIn.readLine() //构建对象 val customer = new Customer(name,gender,age,tel,email) customerService.add(customer) println("添加成功") }
删除客户
Service
复制代码
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//根据ID找到index索引 def findIndexByID(id:Int)= { //遍历customers var index = -1; //默认-1 ,没有找到就返回-1 breakable { for (i <- 0 until customers.length) { if (customers(i).id == id) { index = i break() } } } index } def delete(id:Int)={ val index = findIndexByID(id) if(index != -1){ //删除 customers.remove(index) true }else{ false } }
View
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19def delete(): Any = { println("-----------------删除客户-------------------") println("请删除客户编号(-1退出)") val id = StdIn.readInt() if(id == -1){ println("error") return } println("确认是否删除(Y/N)") val choice = StdIn.readChar().toUpper if(choice == 'Y'){ if(customerService.delete(id)){ println("-----------删除完成-----------") return } } println("-----------删除没有完成-----------")
最后
以上就是搞怪网络最近收集整理的关于客户信息管理系统一.开发流程二.需求分析三.设计的全部内容,更多相关客户信息管理系统一内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复