项目开发流程

  1. 需求分析:懂技术 懂业务
  2. 设计阶段
  3. 实现阶段(代码)
  4. 测试阶段
  5. 实施阶段
  6. 维护阶段

家庭收记账

1 面向过程

package main

import "fmt"

func main()  {
	key:=""
	loop :=true
	balance:=10000.0
	money:=0.0
	note:=""
	details:="收支\t账号金额\t收支金额\t 说 明:"
	ifdomoney:= false

	for{

		fmt.Printf("****************家庭收记账软件****************\n")
		fmt.Printf("----------------1 收支明细----------------\n")
		fmt.Printf("----------------2 登记收入----------------\n")
		fmt.Printf("----------------3 登记支出----------------\n")
		fmt.Printf("----------------4 退出软件----------------\n")
		fmt.Printf("请选择(1-4:)----------------")
		fmt.Scanln(&key)
		switch key {
				case "1":
					if ifdomoney{
						fmt.Printf("----------------1 收支明细----------------\n")
						fmt.Printf("%v ",details	)
					}else {
						fmt.Println("无明细,请来一笔收支吧")
					}


					fmt.Printf("\n\n\n")
				case "2":
					fmt.Println("本次收入金额")
					fmt.Scanln(&money)
					balance+=money
					fmt.Println("本次收入说明")
					fmt.Scanln(&note)
					ifdomoney=true
					details+=fmt.Sprintf("\n收入\t %v \t +%v  \t %v",balance,money,note)
				case "3":
					fmt.Println("登记支出")
					if money >balance{
						fmt.Println("余额不足,无法支出")
						break
					}
					fmt.Println("本次支出金额")
					fmt.Scanln(&money)
					balance-=money
					fmt.Println("本次收入说明")
					fmt.Scanln(&note)
					ifdomoney=true
					details+=fmt.Sprintf("\n支出\t %v \t -%v  \t %v",balance,money,note)
				case "4":
					fmt.Println("确定退出吗? y/n")
					choice:=""
					for {
						fmt.Scanln(&choice)
						if choice=="y"|| choice=="n"{
							break

						}
						fmt.Println("输入有误")
					}
					if choice=="y"{
						loop=false
					}

				default:
					fmt.Printf("input is error\n")
				fmt.Println("loop为:",loop)
		}
		if !loop {
			break
		}



	}


	fmt.Printf("----------------已退出软件----------------")

}

面向对象:

package utils

import "fmt"

//封装到机构

type  FamilyAccount struct {
	key string
	loop bool
	balance float64
	money float64
	note string
	details string
	ifdomoney bool

}

func NewFamilyAccount() *FamilyAccount {
	return &FamilyAccount{
		key:"",
		loop :true,
		balance:10000.0,
		money:0.0,
		note:"",
		details:"收支\t账号金额\t收支金额\t 说 明:",
		ifdomoney:false,
	}
	
}

func (f *FamilyAccount) showDetails(){
	if f.ifdomoney{
		fmt.Printf("----------------1 收支明细----------------\n")
		fmt.Printf("%v ",f.details	)
	}else {
		fmt.Println("无明细,请来一笔收支吧")
	}


	fmt.Printf("\n\n\n")

}

func (f *FamilyAccount) income()  {
	fmt.Println("本次收入金额")
	fmt.Scanln(&f.money)
	f.balance+=f.money
	fmt.Println("本次收入说明")
	fmt.Scanln(&f.note)
	f.ifdomoney=true
	f.details+=fmt.Sprintf("\n收入\t %v \t +%v  \t %v",f.balance,f.money,f.note)
}
func (f *FamilyAccount)  pay() {
	fmt.Println("登记支出")
	if f.money >f.balance{
		fmt.Println("余额不足,无法支出")
		//break
	}
	fmt.Println("本次支出金额")
	fmt.Scanln(&f.money)
	f.balance-=f.money
	fmt.Println("本次收入说明")
	fmt.Scanln(&f.note)
	f.ifdomoney=true
	f.details+=fmt.Sprintf("\n支出\t %v \t -%v  \t %v",f.balance,f.money,f.note)

}
func (f *FamilyAccount) exit() {
	fmt.Println("确定退出吗? y/n")
	choice:=""
	for {
		fmt.Scanln(&choice)
		if choice=="y"|| choice=="n"{
			break

		}
		fmt.Println("输入有误")
	}
	if choice=="y"{
		f.loop=false
	}

}

func (f *FamilyAccount)  ManiMenu() {

	for{

		fmt.Printf("****************家庭收记账软件****************\n")
		fmt.Printf("----------------1 收支明细----------------\n")
		fmt.Printf("----------------2 登记收入----------------\n")
		fmt.Printf("----------------3 登记支出----------------\n")
		fmt.Printf("----------------4 退出软件----------------\n")
		fmt.Printf("请选择(1-4:)----------------")
		fmt.Scanln(&f.key)
		switch f.key {
		case "1":
			f.showDetails()
		case "2":
			f.income()
		case "3":
			f.pay()
		case "4":
			f.exit()

		default:
			fmt.Printf("input is error\n")
			fmt.Println("loop为:",f.loop)
		}
		if !f.loop {
			break
		}

	}

	fmt.Printf("----------------已退出软件----------------")


}

func main()  {



}

mian.go

package main

import (
	"awesomeProject/oopTest1/utils"
)

func main()  {
	utils.NewFamilyAccount().ManiMenu()
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值