当前位置: 首页 > news >正文

海外服务器哪家好免费的seo网站下载

海外服务器哪家好,免费的seo网站下载,济南家居行业网站开发,新疆乌鲁木齐旅游攻略项目 文章目录 项目1.项目开发流程图2.家庭收支记账软件项目2)项目代码实现3)具体功能实现 3.客户信息管理系统1)项目需求说明2)界面设计3)项目框架图4)流程5)完成显示客户列表的功能6&#xff…

项目

文章目录

    • 项目
      • 1.项目开发流程图
      • 2.家庭收支记账软件项目
        • 2)项目代码实现
        • 3)具体功能实现
      • 3.客户信息管理系统
        • 1)项目需求说明
        • 2)界面设计
        • 3)项目框架图
        • 4)流程
        • 5)完成显示客户列表的功能
        • 6)添加客户功能
        • 7)删除客户功能
        • 8)修改客户的功能
        • 9)完整代码的展示如下

1.项目开发流程图

在这里插入图片描述

2.家庭收支记账软件项目

1)需求说明

  • 模拟实现基于文本界面的《家庭记账软件》

  • 该软件能够记录家庭的收入、支出,并能够打印收支明细表

  • 项目采用分级菜单的方式,主菜单如下:

    --------家庭收支记账软件-------1.收支明细2.登记收入3.登记支出4.退出请选择(1-4):
2)项目代码实现

实现基本功能(先使用面向过程,后面改成面向对象)

编写文件TestMyAccount.go 完成基本功能

  1. 功能1:先完成可以显示主菜单,并且可以退出
  2. 功能2:完成可以显示明细和登记收入的功能
  3. 功能3:完成了登记支出的功能
3)具体功能实现

功能1:先完成可以显示主菜单,并且可以退出

思路分析:给出的界面完成,主菜单的显示,当用户输入4的时候就退出

package main
import ("fmt"
)func main(){//声明一个变量,保存接收用户输入的选项key := ""//声明一个变量,控制是否退出for循环loop := true//显示这个主菜单for {fmt.Println("--------家庭收支记账软件---------")fmt.Println("         1.收支明细")fmt.Println("         2.登记收入")fmt.Println("         3.登记支出")fmt.Println("         4.退出软件")fmt.Print("请选择(1-4)")fmt.Scanln(&key)switch key {case "1" :fmt.Println("1.收支明细")case "2" :fmt.Println("2.登记收入")case "3" :fmt.Println("3.登记支出")case "4" :loop = false	default :fmt.Println("请输入正确的选项")			}if !loop {break}}fmt.Println("你退出了家庭记账软件的使用")
}

功能2:完成可以显示明细和登记收入的功能

思路分析:

1.因为需要显示明细,我们定义一个变量details string来记录

2.还需要定义变量来记录余额(balance),每次支出的收支的金额(money),以及收支说明(note)

走代码

    //声明一个变量统计余额balance := 10000.0//每次收支的金额money := 0.0//每次收支的说明note := ""//收支的详情//当有收支发生的时候,就对details进行拼接处理details := "收支\t账户余额\t收支金额\t说明"case的操作
case "2" :fmt.Println("本次收入金额:")fmt.Scanln(&money)balance += money //修改账户余额fmt.Println("本次收入的说明:")fmt.Scanln(&note)//将这个收入情况,拼接到details变量当中details += fmt.Sprintf("\n收入\t%v\t%v\t%v",balance,money,note)

功能3完成登记支出的功能

思路分析:登记支出的功能和登记收入的功能类似做一些修改即可

case "3" :fmt.Println("本次支出的金额:")fmt.Scanln(&money)//这里需要做出一个必要的判断if money > balance {fmt.Println("余额不足")break}balance -=moneyfmt.Println("本次的支出说明:")fmt.Scanln(&note)details += fmt.Sprintf("\n支出\t%v\t%v\t%v",balance,money,note)

项目改进

1.用户输入4时,给出提示"你确定要退出吗?y/n",必须输入正确的y/n,否则循环输入指令,直到输入y或者n

case "4" :fmt.Println("您确定要退出吗? y/n")choice :=" "for {fmt.Scanln(&choice)if choice == "y" || choice == "n"{ //输了y/n就break出去break}fmt.Println("您的输入有误请重新输入 y/n")}if choice == "y" {loop = false	}

2.当没有任何收支明细时,提示“当前没有收支明细。。。来一笔把!”

case "1" :fmt.Println("------------当前收支明细记录--------")if flag {fmt.Println(details)}else{fmt.Println("您当前没有支出记录,来一笔吧!")}

3.在支出时,判断余额是否够,并给出相应的提示

case "3" :fmt.Println("本次支出的金额:")fmt.Scanln(&money)//这里需要做出一个必要的判断if money > balance {fmt.Println("余额不足")break}balance -=moneyfmt.Println("本次的支出说明:")fmt.Scanln(&note)details += fmt.Sprintf("\n支出\t%v\t%v\t%v",balance,money,note)flag = true

面向过程的家庭记账收支软件全部代码

package main
import ("fmt"
)func main(){//声明一个变量,保存接收用户输入的选项key := ""//声明一个变量,控制是否退出for循环loop := true//声明一个变量统计余额balance := 10000.0//每次收支的金额money := 0.0//每次收支的说明note := ""//定义一个变量记录是否有收支的行为flag := false//收支的详情//当有收支发生的时候,就对details进行拼接处理details := "收支\t账户余额\t收支金额\t说明"//显示这个主菜单for {fmt.Println("\n--------家庭收支记账软件---------")fmt.Println("         1.收支明细")fmt.Println("         2.登记收入")fmt.Println("         3.登记支出")fmt.Println("         4.退出软件")fmt.Print("请选择(1-4)")fmt.Scanln(&key)switch key {case "1" :fmt.Println("------------当前收支明细记录--------")if flag {fmt.Println(details)}else{fmt.Println("您当前没有支出记录,来一笔吧!")}case "2" :fmt.Println("本次收入金额:")fmt.Scanln(&money)balance += money //修改账户余额fmt.Println("本次收入的说明:")fmt.Scanln(&note)//将这个收入情况,拼接到details变量当中details += fmt.Sprintf("\n收入\t%v\t%v\t%v",balance,money,note)flag = truecase "3" :fmt.Println("本次支出的金额:")fmt.Scanln(&money)//这里需要做出一个必要的判断if money > balance {fmt.Println("余额不足")break}balance -=moneyfmt.Println("本次的支出说明:")fmt.Scanln(&note)details += fmt.Sprintf("\n支出\t%v\t%v\t%v",balance,money,note)flag = truecase "4" :fmt.Println("您确定要退出吗? y/n")choice :=" "for {fmt.Scanln(&choice)if choice == "y" || choice == "n"{ //输了y/n就break出去break}fmt.Println("您的输入有误请重新输入 y/n")}if choice == "y" {loop = false	}default :fmt.Println("请输入正确的选项")	}if !loop {break}}fmt.Println("你退出了家庭记账软件的使用")
}

4.将面向过程的代码改为面向对象的方法编写myFamilyAccount.go,并使用testMyFamilyAccount.go去完成测试。

思路分析

把记账软件的功能封装到一个结构体中,然后调用该结构体的方法来实现记账,显示明细就可以了,结构体的名字为FamilyAccount

再通过main方法中创建一个结构体FamilyAccount实例,实现记账即可

代码实现,代码不需要重新写,只需要引用上侧代码

package objectTestAcc
import ("fmt"
)type FamilyAccount struct {//声明必须字段//声明一个字段,保存接收用户输入的选项key string//声明一个字段,控制是否退出for循环loop bool//声明一个字段统计余额balance float64//每次收支的金额money float64//每次收支的说明note string//定义一个字段记录是否有收支的行为flag bool//收支的详情//当有收支发生的时候,就对details进行拼接处理details string
}
//编写一个构造方法返回一个FamilyAccount实例 
func NewFamilyAccount() *FamilyAccount {return &FamilyAccount{key : "",loop : true,balance : 10000.0,money : 0.0,note : "",flag : false,details :  "收支\t账户余额\t收支金额\t说明",}
}//将显示明细写成一个方法
func (this *FamilyAccount) ShowDetails(){fmt.Println("------------当前收支明细记录--------")if this.flag {fmt.Println(this.details)}else{fmt.Println("您当前没有支出记录,来一笔吧!")}
}//将登记收入写成一个方法和*FamilyAccount绑定
func (this *FamilyAccount) Income(){fmt.Println("本次收入金额:")fmt.Scanln(&this.money)this.balance += this.money //修改账户余额fmt.Println("本次收入的说明:")fmt.Scanln(&this.note)//将这个收入情况,拼接到details变量当中this.details += fmt.Sprintf("\n收入\t%v\t%v\t%v",this.balance,this.money,this.note)this.flag = true
}
//将支出也绑定到一个方法当中
func (this *FamilyAccount) Pay(){fmt.Println("本次支出的金额:")fmt.Scanln(&this.money)//这里需要做出一个必要的判断if this.money > this.balance {fmt.Println("余额不足")}this.balance -=this.moneyfmt.Println("本次的支出说明:")fmt.Scanln(&this.note)this.details += fmt.Sprintf("\n支出\t%v\t%v\t%v",this.balance,this.money,this.note)this.flag = true
}//将退出系统写成一个方法
func (this *FamilyAccount) exit(){fmt.Println("您确定要退出吗? y/n")choice :=" "for {fmt.Scanln(&choice)if choice == "y" || choice == "n"{ //输了y/n就break出去break}fmt.Println("您的输入有误请重新输入 y/n")}if choice == "y" {this.loop = false	}
}//为该结构体绑定相应的方法
//显示主菜单
func (this *FamilyAccount) MainMenu(){for {fmt.Println("\n--------家庭收支记账软件---------")fmt.Println("         1.收支明细")fmt.Println("         2.登记收入")fmt.Println("         3.登记支出")fmt.Println("         4.退出软件")fmt.Print("请选择(1-4)")fmt.Scanln(&this.key)switch this.key {case "1" :this.ShowDetails()case "2" :this.Income()case "3" :this.Pay()case "4" :this.exit()	default :fmt.Println("请输入正确的选项")	}if !this.loop {break}}
}
建立一个main方法
package main
import ("fmt""go_code/project/objectTestAcc"
)func main() {fmt.Println("这个是面向对象的方式完成")objectTestAcc.NewFamilyAccount().MainMenu()}

3.客户信息管理系统

1)项目需求说明

模拟实现基于文本界面的《客户信息管理软件》

该软件能够实现对客户对象的插入、修改和删除(用切片实现),并能够打印客户明细表 多个对象协同工作

2)界面设计

在这里插入图片描述

添加客户界面

在这里插入图片描述

修改客户界面

在这里插入图片描述

删除客户界面

在这里插入图片描述

客户列表的界面

在这里插入图片描述

3)项目框架图

在这里插入图片描述

4)流程

功能说明

当用户运行程序,可以看到主菜单,当输入5时,可以退出该软件

思路分析

编写customerView.go另外可以把customer.go和customerDervice.go协商

代码实现

customerManager/model/customer.go

package model
// import (
// 	"fmt"
// )
//声明一个customer结构体,表示一个客户信息
type Customer struct {Id intName stringGender stringAge intPhone stringEmail string
}//编写一个工厂模式,返回一个Customer的实例func NewCustomer(id int,name string, gender string,age int,phone string,email string) Customer {return Customer{Id : id,Name : name,Gender : gender,Age : age,Phone : phone,Email : email,}}

customerManagerservice/customerService.go

package service
import ("go_code/project/customerManager/model"
)//该CustomerService ,完成对Customer的操作,包括增删改查
type CustomerService struct {customers []model.Customer//声明一个字段,表示当前切片含有多少客户//该字段后面,还可以作为新客户的id+1customerNum int
}

customerManager/view/customerView.go

package main
import ("fmt"
)type customerView struct {//定义必要字段key string //接收用户输入loop bool //是否循环显示菜单}//显示主菜单
func (this *customerView) mainView() {for{fmt.Println("--------客户信息管理系统------------")fmt.Println("         1.添加客户   ")fmt.Println("         2.修改客户   ")fmt.Println("         3.删除客户   ")fmt.Println("         4.客户列表   ")fmt.Println("         5.退出   ")fmt.Println("请选择(1-5): ")fmt.Scanln(&this.key)switch this.key {case "1":fmt.Println("添加客户")case "2":fmt.Println("修改客户")case "3":fmt.Println("删除客户")case "4":fmt.Println("客户列表")case "5":this.loop = falsedefault :fmt.Println("你的输入有误,请重新输入...")						}if !this.loop {break}}fmt.Println("你退出了客户关系管理系统的使用")
}
func main() {//在主函数中,创建一个customerView并运行显示主菜单...customerView := customerView{key : "",loop : true,	}//显示主菜单customerView.mainView()
}
5)完成显示客户列表的功能

思路分析

在这里插入图片描述

代码实现

customerManager/model/customer.go

package model
import ("fmt"
)
//声明一个customer结构体,表示一个客户信息
type Customer struct {Id intName stringGender stringAge intPhone stringEmail string
}//编写一个工厂模式,返回一个Customer的实例func NewCustomer(id int,name string, gender string,age int,phone string,email string) Customer {return Customer{Id : id,Name : name,Gender : gender,Age : age,Phone : phone,Email : email,}
}
//增加了这个方法
//返回用户的信息,格式化的字符串
func (this Customer) GetInfo() string{info := fmt.Sprintf("%v\t%v\t%v\t%v\t%v\t%v\t",this.Id,this.Name,this.Gender,this.Age,this.Phone,this.Email)return info
} 

customerManagerservice/customerService.go

package service
import ("go_code/project/customerManager/model"
)//该CustomerService ,完成对Customer的操作,包括增删改查
type CustomerService struct {customers []model.Customer//声明一个字段,表示当前切片含有多少客户//该字段后面,还可以作为新客户的id+1customerNum int
}//编写一个方法,可以返回一个*customerService实例
func NewCustomerService() *CustomerService {//为了可以看到客户在切片中,我们初始化一个客户customerService := &CustomerService{}customerService.customerNum = 1customer := model.NewCustomer(1,"张三","男",20,"112","zs@sohu.com")customerService.customers = append(customerService.customers ,customer)return customerService
}//返回客户切片
func (this *CustomerService) List()[]model.Customer{return this.customers
}

customerManager/view/customerView.go

package main
import ("fmt""go_code/project/customerManager/service"
)type customerView struct {//定义必要字段key string //接收用户输入loop bool //是否循环显示菜单//增加一个字段customerServicecustomerService   *service.CustomerService
}//显示所有的客户信息
func (this *customerView) list(){//首先获取到当前所有的客户信息(在切片中)customers := this.customerService.List()//显示fmt.Println("----------客户列表--------------")fmt.Println("编号\t姓名\t性别\t年龄\t电话\t邮箱")for i :=0;i<len(customers);i++ {fmt.Println(customers[i].GetInfo())}fmt.Printf("\n--------客户列表完成------------\n\n")
}//显示主菜单
func (this *customerView) mainView() {for{fmt.Println("--------客户信息管理系统------------")fmt.Println("         1.添加客户   ")fmt.Println("         2.修改客户   ")fmt.Println("         3.删除客户   ")fmt.Println("         4.客户列表   ")fmt.Println("         5.退出   ")fmt.Println("请选择(1-5): ")fmt.Scanln(&this.key)switch this.key {case "1":fmt.Println("添加客户")case "2":fmt.Println("修改客户")case "3":fmt.Println("删除客户")case "4":this.list()case "5":this.loop = falsedefault :fmt.Println("你的输入有误,请重新输入...")						}if !this.loop {break}}fmt.Println("你退出了客户关系管理系统的使用")
}
func main() {//在主函数中,创建一个customerView并运行显示主菜单...customerView := customerView{key : "",loop : true,	}//完成对customerView结构体的customerService字段的初始化customerView.customerService = service.NewCustomerService()//显示主菜单customerView.mainView()
}
6)添加客户功能

功能说明

在这里插入图片描述

思路分析

在这里插入图片描述

代码实现

需要编写CustomerView和customerService,Customer类

规定,新添加的学院的id就是他是第几个加入的

customerManager/model/customer.go

//编写一个工厂模式,返回二种Customer的实例方法,不带id
func NewCustomer2(name string, gender string,age int,phone string,email string) Customer {return Customer{Name : name,Gender : gender,Age : age,Phone : phone,Email : email,}
}

customerManagerservice/customerService.go

增加一个方法
//添加客户到customer切片中
func (this *CustomerService) Add(customer model.Customer) bool{//我们确定一个分配id的规则,就是添加的顺序this.customerNum ++customer.Id = this.customerNumthis.customers = append(this.customers,customer)return true
}

customerManager/view/customerView.go

编写一个add方法调用servic蹭的Add()
//得到用户的输入,信息构建新的客户,并完成添加
func (this *customerView) add() {fmt.Println("------------添加客户------------")fmt.Println("姓名:")name := ""fmt.Scanln(&name)fmt.Println("性别:")gender := ""fmt.Scanln(&gender)fmt.Println("年龄:")age := 0fmt.Scanln(&age)fmt.Println("电话号码:")phone := ""fmt.Scanln(&phone)fmt.Println("电邮:")email := ""fmt.Scanln(&email)//构建一个新的Customer实例//注意:id号没有让用户输入,id号是唯一的,让系统分配即可customer := model.NewCustomer2(name,gender,age,phone,email)//调用if this.customerService.Add(customer) {fmt.Println("------------添加完成------------")}else{fmt.Println("------------添加失败------------")}
}
下面的switch方法也要改一下
case "1":this.add()
7)删除客户功能

功能说明

在这里插入图片描述

思路分析

需要编写CustomerView和CustomerService

在这里插入图片描述

代码实现

customerManager/model/customer.go:无变化

customerManagerservice/customerService.go

增加了这两个方法,一个删除一个查找id
//根据id删除客户(从切片中删除)
func (this *CustomerService) Delete(id int )bool {index :=this.FindById(id)//如果index ==-1说明没有这个客户if index== -1 {return false}//如何从切片中删除一个元素this.customers = append(this.customers[:index],this.customers[index+1:]...)return true}//根据Id查找客户在在切片对应中的下标,返回-1
func (this *CustomerService) FindById(id int) int {//默认为-1index := -1//遍历this.customers切片for i :=0;i < len(this.customers);i++ {if this.customers[i].Id ==id {//找到了index = i}}return index
}

customerManager/view/customerView.go

增加这个方法
//得到用户输入的id删除该id对应的客户
func (this *customerView) delete() {fmt.Println("------------删除客户------------")fmt.Println("请选择待删除的客户编号(-1退出):")id :=-1fmt.Scanln(&id)if id == -1 {return //放弃删除操作}fmt.Println("确认是否删除(Y/N): ")choice := ""fmt.Scanln(&choice)if choice == "y" || choice == "Y" {//调用service中的delete方法if this.customerService.Delete(id) {fmt.Println("------------删除成功------------")}else{fmt.Println("------------删除失败,输入的id号不存在------------")}}
}

8)完善退出确认功能

功能说明:

要求用户在退出时提示“是否退出(Y/N),用户必须输入y/n否则循环提示

思路分析:需编写CustomerView

代码实现

在customerManager/view/customerView.go增加这个方法

//退出软件
func (this *customerView) exit(){fmt.Println("确定是否退出(Y/N): ")for {fmt.Scanln(&this.key)if this.key == "Y" || this.key == "y" || this.key == "N" || this.key == "n"{break}fmt.Println("您的输入有误,请重新输入(Y/N) : ")}if this.key == "Y" || this.key == "y" {this.loop = false}
}
然后在switch中修改一下
case "5":this.exit()
8)修改客户的功能

功能说明:根据id进行对客户的修改操作

思路:依旧在customerService和customerView中进行编写操作

代码实现

customerManagerservice/customerService.go

//根据id进行修改客户信息的操作
func (this *CustomerService) Update(customer model.Customer) bool {index :=this.FindById(customer.Id)//如果index ==-1说明没有这个客户if index== -1 {return false}//将customer插入到指定的位置并对customers进行更新操作,就将原来位置的customer用一个新的customer进行替换操作this.customers = append(append(this.customers[:index],customer),this.customers[index+1:]...)return true
}//根据Id查找客户在在切片对应中的下标,返回-1
func (this *CustomerService) FindById(id int) int {//默认为-1index := -1//遍历this.customers切片for i :=0;i < len(this.customers);i++ {if this.customers[i].Id ==id {//找到了index = i}}return index
}

customerManager/view/customerView.go

//修改客户的操作
func (this *customerView) update() {fmt.Println("------------修改客户------------")fmt.Println("请选择修改客户的编号(-1的话就退出): ")id := -1fmt.Scanln(&id)if id == -1 {return}fmt.Println("姓名:")name := ""fmt.Scanln(&name)fmt.Println("性别:")gender := ""fmt.Scanln(&gender)fmt.Println("年龄:")age := 0fmt.Scanln(&age)fmt.Println("电话号码:")phone := ""fmt.Scanln(&phone)fmt.Println("电邮:")email := ""fmt.Scanln(&email)//构建一个新的Customer实例//注意:id号没有让用户输入,id号是唯一的,让系统分配即可customer := model.NewCustomer(id,name,gender,age,phone,email)//调用if this.customerService.Update(customer) {fmt.Println("------------修改成功------------")}else{fmt.Println("------------修改失败------------")}
}

再外加一个简单的登录操作使得项目更加完善

在customerManager/view/customerView.go中进行编写

//简单登录功能的时间
func (this *customerView) Login (){account :=""pwd :=""for {fmt.Println("请输入账号: ")fmt.Scanln(&account)fmt.Println("请输入密码")fmt.Scanln(&pwd)if account == "7758258" && pwd =="111"{fmt.Println("恭喜你!正在进入系统!")break}fmt.Println("您的输入的账号或者密码有误,请重新输入: ")	   	}this.mainView()
}
func main() {//在主函数中,创建一个customerView并运行显示主菜单...customerView := customerView{key : "",loop : true,	}//完成对customerView结构体的customerService字段的初始化customerView.customerService = service.NewCustomerService()//显示主菜单customerView.Login()
}
9)完整代码的展示如下

customerManager/model/customer.go

package model
import ("fmt"
)
//声明一个customer结构体,表示一个客户信息
type Customer struct {Id intName stringGender stringAge intPhone stringEmail string
}//编写一个工厂模式,返回一个Customer的实例
func NewCustomer(id int,name string, gender string,age int,phone string,email string) Customer {return Customer{Id : id,Name : name,Gender : gender,Age : age,Phone : phone,Email : email,}
}//编写一个工厂模式,返回二种Customer的实例方法,不带id
func NewCustomer2(name string, gender string,age int,phone string,email string) Customer {return Customer{Name : name,Gender : gender,Age : age,Phone : phone,Email : email,}
}//返回用户的信息,格式化的字符串
func (this Customer) GetInfo() string{info := fmt.Sprintf("%v\t%v\t%v\t%v\t%v\t%v\t",this.Id,this.Name,this.Gender,this.Age,this.Phone,this.Email)return info
} 

customerManagerservice/customerService.go

package service
import ("go_code/project/customerManager/model"
)//该CustomerService ,完成对Customer的操作,包括增删改查
type CustomerService struct {customers []model.Customer//声明一个字段,表示当前切片含有多少客户//该字段后面,还可以作为新客户的id+1customerNum int
}//编写一个方法,可以返回一个*customerService实例
func NewCustomerService() *CustomerService {//为了可以看到客户在切片中,我们初始化一个客户customerService := &CustomerService{}customerService.customerNum = 1customer := model.NewCustomer(1,"张三","男",20,"112","zs@sohu.com")customerService.customers = append(customerService.customers ,customer)return customerService
}//返回客户切片
//一定要使用指针的方式
func (this *CustomerService) List()[]model.Customer{return this.customers
}//添加客户到customer切片中
//必须要用指针的方式,保证一直用的都是一个CustomerService
func (this *CustomerService) Add(customer model.Customer) bool{//我们确定一个分配id的规则,就是添加的顺序this.customerNum ++customer.Id = this.customerNumthis.customers = append(this.customers,customer)return true
}//根据id删除客户(从切片中删除)
func (this *CustomerService) Delete(id int )bool {index :=this.FindById(id)//如果index ==-1说明没有这个客户if index== -1 {return false}//如何从切片中删除一个元素this.customers = append(this.customers[:index],this.customers[index+1:]...)return true}//根据id进行修改客户信息的操作
func (this *CustomerService) Update(customer model.Customer) bool {index :=this.FindById(customer.Id)//如果index ==-1说明没有这个客户if index== -1 {return false}//将customer插入到指定的位置并对customers进行更新操作,就将原来位置的customer用一个新的customer进行替换操作this.customers = append(append(this.customers[:index],customer),this.customers[index+1:]...)return true
}//根据Id查找客户在在切片对应中的下标,返回-1
func (this *CustomerService) FindById(id int) int {//默认为-1index := -1//遍历this.customers切片for i :=0;i < len(this.customers);i++ {if this.customers[i].Id ==id {//找到了index = i}}return index
}

customerManager/view/customerView.go

package main
import ("fmt""go_code/project/customerManager/service""go_code/project/customerManager/model"
)type customerView struct {//定义必要字段key string //接收用户输入loop bool //是否循环显示菜单//增加一个字段customerServicecustomerService   *service.CustomerService
}//显示所有的客户信息
func (this *customerView) list(){//首先获取到当前所有的客户信息(在切片中)customers := this.customerService.List()//显示fmt.Println("----------客户列表--------------")fmt.Println("编号\t姓名\t性别\t年龄\t电话\t邮箱")for i :=0;i<len(customers);i++ {fmt.Println(customers[i].GetInfo())}fmt.Printf("\n--------客户列表完成------------\n\n")
}//得到用户的输入,信息构建新的客户,并完成添加
func (this *customerView) add() {fmt.Println("------------添加客户------------")fmt.Println("姓名:")name := ""fmt.Scanln(&name)fmt.Println("性别:")gender := ""fmt.Scanln(&gender)fmt.Println("年龄:")age := 0fmt.Scanln(&age)fmt.Println("电话号码:")phone := ""fmt.Scanln(&phone)fmt.Println("电邮:")email := ""fmt.Scanln(&email)//构建一个新的Customer实例//注意:id号没有让用户输入,id号是唯一的,让系统分配即可customer := model.NewCustomer2(name,gender,age,phone,email)//调用if this.customerService.Add(customer) {fmt.Println("------------添加完成------------")}else{fmt.Println("------------添加失败------------")}
}//修改客户的操作
func (this *customerView) update() {fmt.Println("------------修改客户------------")fmt.Println("请选择修改客户的编号(-1的话就退出): ")id := -1fmt.Scanln(&id)if id == -1 {return}fmt.Println("姓名:")name := ""fmt.Scanln(&name)fmt.Println("性别:")gender := ""fmt.Scanln(&gender)fmt.Println("年龄:")age := 0fmt.Scanln(&age)fmt.Println("电话号码:")phone := ""fmt.Scanln(&phone)fmt.Println("电邮:")email := ""fmt.Scanln(&email)//构建一个新的Customer实例//注意:id号没有让用户输入,id号是唯一的,让系统分配即可customer := model.NewCustomer(id,name,gender,age,phone,email)//调用if this.customerService.Update(customer) {fmt.Println("------------修改成功------------")}else{fmt.Println("------------修改失败------------")}
}//得到用户输入的id删除该id对应的客户
func (this *customerView) delete() {fmt.Println("------------删除客户------------")fmt.Println("请选择待删除的客户编号(-1退出):")id :=-1fmt.Scanln(&id)if id == -1 {return //放弃删除操作}fmt.Println("确认是否删除(Y/N): ")choice := ""for {fmt.Scanln(&choice)if choice == "y" || choice == "Y" || choice =="n" || choice =="N"{break}fmt.Println("您的输入有误请重新输入(Y/N): ")}if choice == "y" || choice == "Y" {//调用service中的delete方法if this.customerService.Delete(id) {fmt.Println("------------删除成功------------")}else{fmt.Println("------------删除失败,输入的id号不存在------------")}} else{this.mainView()}
}//退出软件
func (this *customerView) exit(){fmt.Println("确定是否退出(Y/N): ")for {fmt.Scanln(&this.key)if this.key == "Y" || this.key == "y" || this.key == "N" || this.key == "n"{break}fmt.Println("您的输入有误,请重新输入(Y/N) : ")}if this.key == "Y" || this.key == "y" {this.loop = false}
}//显示主菜单
func (this *customerView) mainView() {for{fmt.Println("--------客户信息管理系统------------")fmt.Println("         1.添加客户   ")fmt.Println("         2.修改客户   ")fmt.Println("         3.删除客户   ")fmt.Println("         4.客户列表   ")fmt.Println("         5.退出   ")fmt.Println("请选择(1-5): ")fmt.Scanln(&this.key)switch this.key {case "1":this.add()case "2":this.update()case "3":this.delete()case "4":this.list()case "5":this.exit()default :fmt.Println("你的输入有误,请重新输入...")						}if !this.loop {break}}fmt.Println("你退出了客户关系管理系统的使用")
}//简单登录功能的时间
func (this *customerView) Login (){account :=""pwd :=""for {fmt.Println("请输入账号: ")fmt.Scanln(&account)fmt.Println("请输入密码")fmt.Scanln(&pwd)if account == "7758258" && pwd =="111"{fmt.Println("恭喜你!正在进入系统!")break}fmt.Println("您的输入的账号或者密码有误,请重新输入: ")	   	}this.mainView()
}
func main() {//在主函数中,创建一个customerView并运行显示主菜单...customerView := customerView{key : "",loop : true,	}//完成对customerView结构体的customerService字段的初始化customerView.customerService = service.NewCustomerService()//显示主菜单customerView.Login()
}

10)项目展示

1.登录

在这里插入图片描述

2.客户列表

在这里插入图片描述

3.添加客户

在这里插入图片描述

4.修改客户

在这里插入图片描述

5.删除客户

在这里插入图片描述

6.退出

在这里插入图片描述

http://www.mmbaike.com/news/43442.html

相关文章:

  • 如何用 python 做网站什么软件可以找客户资源
  • 如何用frontpage2003做网站宁波seo外包引流推广
  • 互联网哪个专业前景好网站搜索引擎优化的方法
  • 微信公众号怎么创建优惠券aso优化排名违法吗
  • 网站如何做淘宝支付宝支付网店运营推广实训
  • 创龙企业方案解决英文seo外链发布工具
  • 服饰类网站开发项目在线之家
  • 成都网站优化方案武汉seo服务外包
  • 西安免费做网站公司杭州线上推广
  • 网站设计版权如何免费建立一个网站
  • 政府门户网站建设的问题seo学习网站
  • 上海市住房和城乡建设部官方网站广州网站优化公司如何
  • 北京平台网站建设费用登录百度账号注册
  • 织梦免费模板dede源码seo厂商
  • 成都网站建设58百度官方推广
  • 卖东西怎么做网站seo辅助优化工具
  • 华为商城网站设计分析市场调研的方法有哪些
  • 北京注册公司代理机构排名宁波搜索引擎优化seo
  • 单页面营销型网站制作网络推广技巧
  • 庆阳网站设计 贝壳下拉推荐6个免费国外自媒体平台
  • 傻瓜式在线做网站德阳seo优化
  • 许昌哪里做网站google搜索下载
  • 哪个网站可以做服装批发衣服友情链接检测平台
  • 海南门户网站开发公司福州百度推广开户
  • 网站开发企业公司手机端关键词排名免费软件
  • 建设网站注意自己做网站网页归档
  • 免费的毕业设计网站建设网络营销软件下载
  • 大悟网站建设万网域名查询
  • 广州专业网站建设公司网站seo关键词排名推广
  • 上海徐汇网站建设网址大全浏览器app