家庭收支软件

package utilsimport "fmt"type FamilyAccount struct {//声明一个变量,保存接收用户输入的选项key string//声明一个变量,控制是否退出forloop bool//定义账户的余额 []balance float64//每次收支的金额money float64//每次收支的说明note string//定义一个变量,记录是否有收支的行为flag bool//收支的详情使用字符串来记录//当有收支是,只需要对details 进行拼接处理即可details string
}//封装成函数func (a *FamilyAccount) showDetail() {fmt.Println("------------当前收支明细记录-------------")if a.flag {fmt.Println(a.details)} else {fmt.Println("当前没有收支.....")}
}func (a *FamilyAccount) income() {fmt.Println("本次收入金额:")fmt.Scanln(&a.money)a.balance += a.moneyfmt.Println("本次收入说明:")fmt.Scanln(&a.note)//将这个收入情况,拼接到details变量a.details += fmt.Sprintf("\n收入\t %v    \t %v \t \t %v", a.balance, a.money, a.note)a.flag = true
}func (a *FamilyAccount) pay() {fmt.Println("本次支出金额:")fmt.Scanln(&a.money)if a.money > a.balance {fmt.Println("余额不足...")return}a.balance -= a.moneyfmt.Println("本次支出说明:")fmt.Scanln(&a.note)//将这个收入情况,拼接到details变量a.details += fmt.Sprintf("\n支出\t %v    \t %v \t \t %v", a.balance, a.money, a.note)a.flag = true
}func (a *FamilyAccount) exit() {fmt.Println("你确定要退出吗?y/n")choice := ""for {fmt.Scanln(&choice)if choice == "y" || choice == "n" {break} else {fmt.Println("你的输入有误,请重新输入 y/n")}}if choice == "y" {a.loop = false}
}//编写工程模式的构造方法,返回应该*FamilyAccount
func NewFamilyAccount() *FamilyAccount {return &FamilyAccount{key:     "",loop:    true,balance: 10000.0,money:   0.0,note:    "",flag:    false,details: "收支\t账户金额\t收支金额\t说   明",}
}//绑定方法
//显示主菜单
func (a *FamilyAccount) MainMenu() {for {fmt.Println("\n-----------家庭收支记账软件-------------")fmt.Println("     1.收支吗明细             ")fmt.Println("     2.登记收入          ")fmt.Println("     3.登记支出")fmt.Println("     4.退去软件              ")fmt.Println("请选择(1-4):")fmt.Scanln(&a.key)switch a.key {case "1":a.showDetail()case "2":a.income()case "3":a.pay()case "4":a.exit()default:fmt.Println("请输入正确选项...")}if !a.loop {break}}fmt.Println("你退出了家庭记账软件...")
}//main包
package mainimport "go_code/project02/famailyaccount/utils"func main() {utils.NewFamilyAccount().MainMenu()}

客户信息管理软件

//model包
package modelimport "fmt"//声明一个Customer结构体,表示客户信息
type Customer struct {Id     intName   stringGender stringAge    intPhone  stringEmail  string
}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 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", this.Id,this.Name, this.Gender, this.Age, this.Phone, this.Email)return info
}
//service包
package serviceimport "go_code/project02/customerMagnage/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, "123", "zs@qq.com")customerService.customers = append(customerService.customers, customer)return customerService
}//返回客户切片
func (this *CustomerService) List() []model.Customer {return this.customers
}//添加客户到customers切片中
func (this *CustomerService) Add(customer model.Customer) bool {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)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 {//遍历index := -1//遍历this.customers 切片for i := 0; i < len(this.customers); i++ {if this.customers[i].Id == id {//找到index = i}}return index
}//根据id修改用户
func (this *CustomerService) UpdateById(index int, customer model.Customer) bool {if index == -1 {return false}this.customers[index].Id = customer.Idthis.customers[index].Age = customer.Agethis.customers[index].Phone = customer.Phonethis.customers[index].Gender = customer.Genderthis.customers[index].Name = customer.Namethis.customers[index].Email = customer.Emailreturn true}
//view包
package mainimport ("fmt""go_code/project02/customerMagnage/model""go_code/project02/customerMagnage/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) 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("----------------添加失败-----------------")}
}//得到用户的输入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" {//调用delete方法if this.customerService.Delete(id) {fmt.Println("---------------删除完成-------------------")} else {fmt.Println("--------删除失败,输入的id号不存在----------")}}}//修改
func (this *customerView) update() {fmt.Println("-----------------修 改 客 户--------------------")this.list()fmt.Println("输入要修改的编号...")var id int = -1fmt.Scanln(&id)index := this.customerService.FindById(id)if index != -1 {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 := model.NewCustomer(id, name, gender, age, phone, email)this.customerService.UpdateById(index, customer)fmt.Println("修改成功......")} else {fmt.Println("修改失败.........")}}//退出软件
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) mainMenu() {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 main() {//在main函数中,创建一个customerView,并运行显示主菜单...customerView := customerView{key:  "",loop: true,}//这里完成对customerview结构体的customerservice字段的初始化customerView.customerService = service.NewCustomerService()customerView.mainMenu()
}

本人博客地址

Golang入门项目(家庭收支软件和客户信息管理软件)相关推荐

  1. Java实现客户信息管理软件

    资源分享: 尚硅谷 链接:https://pan.baidu.com/s/1B_liAbYxos9voDuFLx-Ldg  提取码:1if5  --来自百度网盘超级会员V6的分享 「Project2( ...

  2. Java小项目—客户信息管理软件(二)

    CustomerView类的设计 CustomerView为主模块,负责菜单的显示和处理用户操作. 本类封装以下信息: 创建最大包含10个客户对象的CustomerList对象,供以下各成员方法使用. ...

  3. 零基础Java学习之初级项目实践(客户信息管理软件-附源码)

    项目涉及知识点 基础的面向对象编程项目. 类和对象(属性.方法及构造器) 类的封装 引用数组 数组的插入.删除和替换 对象的聚集处理 多对象协同工作 需求说明 总体说明 模拟实现基于文本界面的< ...

  4. Java基础项目——客户信息管理软件

    目录 前言 本项目目标 一.需求及软件设计结构说明 1.需求说明 1)主菜单 2)添加客户 3)修改客户 4)删除客户 5)客户列表 2.软件设计结构 1)Customer类的设计 2)Custome ...

  5. Java 简单控制台项目之客户信息管理软件 --- 凌宸1642

    项目二:客户信息管理软件 模拟实现一个基于文本界面的<客户信息管理软件> 进一步掌握编程技巧和调试技巧,熟悉面向对象编程 主要涉及以下知识点: 类结构的使用:属性.方法及构造器 对象的创建 ...

  6. P001【项目一】客户信息管理软件_Customer类(2)

    客户信息管理软件_问题描述汇总 Customer 类的详细代码 CustomerList 类的详细代码 CustomerView 类的详细代码 CMutility 类的详细代码 实体对象Custome ...

  7. Java项目二——客户信息管理软件

    目录 1.CMUtility工具类 2.客户类:Customer 3.客户信息管理类:CustomerList 4.CustomerView为主模块 二.程序的运行结果展示 1.添加客户 2.修改客户 ...

  8. java se 学习之项目二:客户信息管理软件

    一.需求说明 模拟实现基于文本界面的<客户信息管理软件>. 该软件能够实现对客户对象的插入.修改和删除(用数组实现),并能够打印客户明细表. 项目采用分级菜单方式.主菜单如下: ----- ...

  9. Java学习路线:day11 客户信息管理软件

    文章目录 转载自atguigu.com视频 客户信息管理软件 需求说明书 软件设计结构 第1步:封装CMUtility工具类 第2步:Customer类的设计 第3步:CustomerList类的设计 ...

最新文章

  1. C++:随笔8---命名空间
  2. LIKE语句也可以这样写
  3. seata+nacos出现failed to req API:/nacos/v1/ns/instance/beat after all servers([127.0.0.1:8848])
  4. java 当一个文本框有值时另一个文本框置灰_【农行DevOps进行时】基于PaaS的持续集成/持续交付实践 | IDCF...
  5. Active Directory的用户属性说明
  6. 【渝粤题库】陕西师范大学291003综合英语(三)作业(高起专、高起本)
  7. 从底层重学 Java 之四大整数 GitChat链接
  8. VMware网络连接模式—桥接、NAT以及仅主机模式的详细介绍和区别
  9. SQL2005学习(三十二),Group by
  10. 尝试一下sql server2016里面的json功能
  11. Python集合框架
  12. python扫雷总结与体会_扫雷项目总结
  13. 【Android 视频硬件编码】在Native层实现MediaCodec H264 编码 Demon
  14. 中兴通讯携MF30打造高速无线网络
  15. php7isapi,如何选择PHP套件中ISAPI和FastCGI模式的版本?_护卫神
  16. 计算机装系统找不到硬盘分区,如果U盘安装系统找不到硬盘分区,该怎么办?...
  17. git使用命令行首次提交代码
  18. 用Excel制作不一样的分割图表
  19. 计算机制作不同数据数据图表,数据图表与分析.doc
  20. 数据集成平台的特点(Oracle service bus)

热门文章

  1. 【文章】找工作那些事儿
  2. Unity 获取手机键盘弹出高度
  3. Lifekeeper实现DB2主备式群集
  4. 完美解决eNSP virtualBox安装完成后只有VirtualBox Host-Only Network #2,Ensp利用虚拟网卡的设备无法启动。eNSP设备AC;AP设备报41错误解决办法。
  5. 小红书最新入驻,小红书入驻细节,小红书商家入驻
  6. 机器学习之红楼梦作者判断(贝叶斯分类)
  7. 计算机丢失P16R16.DLL,【泓格PISO-P16R16U/PEX-P16R16i/PEX-P8R8i】价格_厂家 - 中国供应商...
  8. 新代系统cnc怎样连接电脑_台湾新代数控系统SYNTEC-CNC应用手册V10-3.pdf
  9. 单片机入门到高级进阶路径(附教程+工具)
  10. ANSYS多相流的单向流固耦合(2022R1版)