概述
客户信息管理系统
文章目录
- 客户信息管理系统
- 1. AppStart
- 2. CustomerView
- 3. CustomerService
- 4. Customer
1. AppStart
package com.guli.chapter15.app
import com.guli.chapter15.customerView.CustomerView
object AppStart {
def main(args: Array[String]): Unit = {
(new CustomerView).meau()
}
}
2. CustomerView
package com.guli.chapter15.customerView
import com.guli.chapter15.customerService.CustomerService
import scala.io.StdIn
class CustomerView {
var customerService = new CustomerService()
def meau(): Unit = {
var flag = true
do {
println("-----------------客户信息管理软件-----------------")
println(" 1 添 加 客 户 ")
println(" 2 修 改 客 户 ")
println(" 3 删 除 客 户 ")
println(" 4 客 户 列 表 ")
println(" 5 查 询 客 户 ")
println(" 6 退 出 ")
println("请选择(1-6): ")
var num = StdIn.readInt()
num match {
case 1 => addClient()
case 2 => updateCli()
case 3 => deleteCli()
case 4 => showList()
case 5 => searchCli()
case 6 => exitApp()
}
} while (flag)
// 退出程序
def exitApp(): Unit = {
print("确认是否退出Y/N:")
val r = StdIn.readLine()
if (r.equals("Y") || r.equals("y")) {
flag = false
println("成功退出程序!Bye~~")
}
}
}
// 显示客户列表
def showList(): Unit = {
println("编号tt" + "姓名tt" + "性别tt" + "年龄tt" + "电话tt" + "邮箱")
customerService.showList(customerService.customers)
}
// 添加客户
def addClient(): Unit = {
customerService.addClient()
}
// 删除客户
def deleteCli() {
print("请输入要删除的客户编号(-1退出):")
val id = StdIn.readInt()
if (id == -1) {
return
}
val index = customerService.findIndexById(id)
if (index != -1) {
print("确认是否删除Y/N:")
val r = StdIn.readLine()
if (r.equals("Y") || r.equals("y")) {
customerService.deleteCli(index)
println("删除成功!")
return
}
}
println("删除失败!")
}
// 修改客户信息
def updateCli(): Unit = {
print("请输入要修改的客户的编号:")
val id = StdIn.readInt()
val index = customerService.findIndexById(id)
if (index == -1) {
print("查无此人!")
return
}
customerService.updateCli(index)
}
// 查询客户
def searchCli(): Unit = {
print("请选择查询方式(1:根据id , 2:根据名字)")
val way = StdIn.readInt()
customerService.serchCli(way)
}
}
3. CustomerService
package com.guli.chapter15.customerService
import com.guli.chapter15.customer.Customer
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.io.StdIn
class CustomerService {
var customers = new ListBuffer[Customer]()
var id = 0
// customers.append(new Customer(1,"zgl",'男',23,"180","zgl@163.com"))
// 显示客户列表
def showList(customers: ListBuffer[Customer]): Unit = {
for (item <- customers) {
println(item)
}
}
// 添加客户
def addClient(): Unit = {
id += 1
print("请输入客户姓名:")
val name = StdIn.readLine()
print("请输入客户性别:")
val sex = StdIn.readChar()
print("请输入客户年龄:")
val age = StdIn.readShort()
print("请输入客户电话:")
val tel = StdIn.readLine()
print("请输入客户邮箱:")
val mail = StdIn.readLine()
customers.append(new Customer(id, name, sex, age, tel, mail))
}
// 查找客户
def findIndexById(id: Int): Int = {
var index = 0
for (item <- customers) {
if (item.id == id) return index
}
-1
}
// 删除客户
def deleteCli(index: Int): Unit = {
customers.remove(index)
}
// 修改客户信息
def updateCli(index: Int) {
val cus = customers(index)
print(s"姓名(${cus.name}):")
val name = StdIn.readLine()
if (name != "") cus.name = name
print(s"性别(${cus.sex}):")
val sex = StdIn.readLine()
if (sex != "") cus.sex = sex.toCharArray()(0)
print(s"年龄(${cus.age}):")
val age = StdIn.readLine()
if (age != "") cus.age = age.toShort
print(s"电话(${cus.tel}):")
val tel = StdIn.readLine()
if (tel != "") cus.tel = tel
print(s"邮箱(${cus.mail}):")
val mail = StdIn.readLine()
if (mail != "") cus.mail = mail
customers.update(index, cus)
println("修改成功!")
}
// 查询客户
def serchCli(way: Int) {
// 根据id查询
if (way == 1) {
print("请输入id:")
val id = StdIn.readInt()
for (item <- customers) {
if (item.id == id) {
println("编号tt" + "姓名tt" + "性别tt" + "年龄tt" + "电话tt" + "邮箱")
println(item)
}
}
} else if (way == 2) {
// 根据姓名查询
print("请输入名字:")
val name = StdIn.readLine()
for (item <- customers) {
if (item.name.contains(name)) {
println("编号tt" + "姓名tt" + "性别tt" + "年龄tt" + "电话tt" + "邮箱")
println(item)
}
}
}
else {
println("输入有误!")
}
}
}
4. Customer
package com.guli.chapter15.customer
class Customer {
var id: Int = _
var name: String = _
var sex: Char = _
var age: Short = _
var tel: String = _
var mail: String = _
def this(id: Int, name: String, sex: Char, age: Short, tel: String, mail: String) {
this
this.id = id
this.name = name
this.sex = sex
this.age = age
this.tel = tel
this.mail = mail
}
override def toString: String = {
this.id + "tt" + this.name + "tt" + this.sex + "tt" + this.age + "tt" + this.tel + "tt" + this.mail
}
}
最后
以上就是美丽棒球为你收集整理的14 Scala 实现客户信息管理系统客户信息管理系统的全部内容,希望文章能够帮你解决14 Scala 实现客户信息管理系统客户信息管理系统所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复