文章目录
-
-
-
- 1.需求了解
- 2.程序目录结构
- 3.原码参考
-
- 3.1
- 3.2
- 3.3 (***)
- 3.4
- 3.5
-
-
1.需求了解
需求文档.md
# card 类 存储卡类
卡号 , 密码 , 余额 , 锁定状态
cardid password money islock
# person 类 用户类
用户名,身份证,手机号,卡
name,userid,phone,card
# view 类 视图类
登录 , 打印欢迎界面 , 打印操作界面
# operation 类 操作类
把十个功能都写在操作类当中
# main 调用十个功能
(1)开户 : register
(2)查询 : query
(3)存钱 : save_money
(4)取钱 : get_money
(5)转账 : trans_money
(6)改密 : change_pwd
(7)锁卡 : lock
(8)解卡 : unlock #
(9)补卡 : new_card #
(10)退出: save
2.程序目录结构
ATM_Demo/
├── 需求文档.md # 程序需求文档
├── # 数据库文件
├── # 数据库文件
├── # 程序运行主文件
├── package/ # 功能包
├──
├──
├──
├──
3.原码参考
3.1
from package.view import View
from package.operation import Operation
class Main():
@staticmethod
def run():
if View.login():
obj=Operation()
while True:
choice = input("请选择需要办理的业务")
if choice == "1":
obj.register()
elif choice == "2":
obj.query()
elif choice == "3":
obj.save_money()
elif choice == "4":
obj.get_money()
elif choice == "5":
obj.trans_money()
elif choice == "6":
obj.change_pwd()
elif choice == "7":
obj.lock()
elif choice == "8":
obj.unlock()
elif choice == "9":
obj.new_card()
elif choice == "0":
obj.save()
break
else:
print("您输入的业务指令有误,请重新选择")
if __name__ == "__main__":
Main.run()
3.2
# ### card 类
# 卡号: cardid 密码:password 余额:money 锁定状态:islock
class Card():
def __init__(self,cardid,password,money):
self.cardid = cardid
self.password = password
self.money = money
#默认新开的卡都不锁
self.islock = False
3.3 (***)
# ### operation 操作类
import re
import pickle
import os
import random
import time
from .card import Card
from .person import Person
class Operation():
def __init__(self):
#加载数据 卡号: 用户对象
self.load_user()
#加载数据 身份证:卡号
self.load_userid()
def load_user(self):
#判断文件是否存在,存在时候就拿数据,否则初始化字典
if os.path.exists(""):
with open("",mode="rb") as fp:
self.user_dict = pickle.load(fp)
else:
self.user_dict = {
}
print(self.user_dict)
def load_userid(self):
if os.path.exists(""):
with open("",mode="rb") as fp:
self.userid_dict = pickle.load(fp)
else:
self.userid_dict = {
}
print(self.userid_dict)
#(0)保存退出 save
def save(self):
with open("",mode="wb") as fp:
pickle.dump(self.user_dict,fp)
with open("",mode="wb") as fp:
pickle.dump(self.userid_dict,fp)
#(1)开户 register
def register(self):
name = self.get_name()
userid=self.get_userid()
phone=self.get_phone()
#获取密码
password = self.get_cwd()
# 获取卡号
cardid = self.get_cardid()
#余额默认为10
money=10
#创建一张