列出对象及属性名称行为...py
'''
人
类名:Person
属性:姓名 身份证号 电话 卡
行为:卡
类名:Card
属性:卡号 密码 余额
行为:银行
类名:Bank
属性:用户列表 提款机提款机
类名:ATM
属性:用户字典
行为:开户 查询 取款 存储 转账 改密 锁定 解锁 补卡 销户界面
类名:View
属性:
行为: 管理员界面 系统功能界面 管理员登陆'''
import time
import pickle
import os
from view import View
from atm import ATMdef main():# 用户管理员开机功能view = View()# 管理员开机view.printAdminView()if view.adminOption():return -1#存储用户所有的信息# allUser = {}#提款机对象filepath = os.path.join(os.getcwd(), "allUsers.txt")f = open(filepath,"rb")allUsers = pickle.load(f)# allUsers = {}atm = ATM(allUsers)print(allUsers)while 1:view.sysFunctionView()#等待用户的操作option = input("请输入您的操作:")if option =="1":atm.creatUser()# print("开户")elif option == "2":atm.serchUserInfo()elif option == "3":atm.getMoney()print("取款")elif option == "4":print("存款")elif option =="5":print("转账")elif option == "6":print("改密")elif option == "7":atm.lockUser()elif option == "8":atm.unlockUser()elif option == "9":print("补卡")elif option == "0":print("销户")elif option == "T":print("退出")if not view.adminOption():#将信息保留到文件中# filepath = os.path.join(os.getcwd(),"allUsers.txt")f= open(filepath,"wb")pickle.dump(atm.allUsers,f)f.close()return -1time.sleep(2)if __name__ =="__main__":main()
atm.py
from card import Card
from user import User
import randomclass ATM (object):def __init__(self,allUsers):self.allUsers = allUsersdef creatUser(self):#目标:想用户字典中添加一对键值对(卡号-用户)name = input("请输入您的姓名:")idCard = input("请输入您的身份证号码:")phone = input("请输入您的电话号码:")prestoreMoney = int(input("请输入预存款金额:"))if prestoreMoney<0:print("输入金额有误!!开户失败")return -1onePasswd = int(input("请设置密码"))#验证密码if not self.checkPasswd(onePasswd):print("密码输入错误输入失败")return -1#所有需要的信息就全了cardStr = self.randomCardId()card = Card(cardStr,onePasswd,prestoreMoney)user= User(name,idCard,phone,card)#存到字典self.allUsers[cardStr] = userprint("开户成功!!请牢记卡号%s!!"%cardStr)#验证密码def checkPasswd(self,realPasswd):for i in range(3):tempPasswd = int(input("请输入密码:"))if tempPasswd == realPasswd:return Truereturn False#生成卡号def randomCardId(self):while True:str = ""for i in range(6):ch = chr(random.randrange(ord('0'), ord('9') + 1))str += ch# 判断是否重复if not self.allUsers.get(str):return strdef serchUserInfo(self):cardNum = input("请输入您要查询的卡号:")user= self.allUsers.get(cardNum)if not user:print("该卡号不存在,查询失败。")return -1#验证密码if not self.checkPasswd(user.card.cardPasswd):print("密码输入错误!!查询失败")return -1print("账号:%s,余额:%d"%(user.card.cardId,user.card.cardMoney))def getMoney(self):cardNum = input("请输入您要查询的卡号:")user = self.allUsers.get(cardNum)if not user:print("该卡号不存在,取款失败。")return -1# 判断是否锁定if user.card.cardLock:print("该卡已被锁定,请解锁后进行其他操作")return -1# 验证密码if not self.checkPasswd(user.card.cardPasswd):print("密码输入错误!!已被锁定解锁后进行其他操作")user.card.cardLock = Truereturn -1#取款money =int(input("请输入取款金额"))if money> user.card.cardMoney:print("余额不足")return -1if money<0:print("输入错误")return -1user.card.cardMoney-=moneyprint("取款成功余额为:%d"%user.card.cardMoney)def saveMoney(self):passdef transforMoney(self):passdef changePasswd(self):passdef lockUser(self):cardNum = input("请输入您要查询的卡号:")user = self.allUsers.get(cardNum)if not user:print("该卡号不存在,锁定失败。")return -1# if user.card.cardLock:# print("该卡号已被锁定!请解锁后再使用其他功能")# return -1#判断是否锁定if user.card.cardLock:print("该卡已被锁定,请解锁后进行其他操作")return -1# 验证密码if not self.checkPasswd(user.card.cardPasswd):print("密码输入错误!!锁定失败")user.card.cardLock = Truereturn -1print("账号:%s,余额:%d" % (user.card.cardId, user.card.cardMoney))tempIdCard = input("请输入您的身份证号:")if tempIdCard!=user.idCard:print("身份证输入错误!!锁定失败")return -1#锁他user.card.cardLock= Trueprint("锁定成功")def unlockUser(self):cardNum = input("请输入您要解锁的卡号:")user = self.allUsers.get(cardNum)if not user:print("该卡号不存在,解锁失败。")return -1if not user.card.cardLock:print("该卡没有锁定!无需解锁。")return -1# 验证密码if not self.checkPasswd(user.card.cardPasswd):print("密码输入错误!!锁定失败")return -1#解锁、user.card.cardLock = Falseprint("解锁成功!")def newCard(self):passdef killUser(self):pass
card.py
class Card(object):def __init__(self,cardId,cardPasswd,cardMoney):self.cardId = cardIdself.cardPasswd = cardPasswdself.cardMoney= cardMoneyself.cardLock = False
user.py
class User(object):def __init__(self,name,idCard,phone,card):self.name = nameself.idCard = idCardself.phone = phoneself.card = card
view.py
import time
class View(object):admin= "1"passwd = "1"# def __init__(self,admin):# self.__admin = admindef printAdminView(self):print("************************************************")print("* *")print("* *")print("* 欢迎登陆旺哥银行 *")print("* *")print("* *")print("************************************************")# inputAdmin = input("请输入管理员账号:")# if self.admin !=inputAdmin:# print("输入有误")# return -1# inputPasswd = input("请输入管理员密码:")# if self.passwd !=inputPasswd:# print("输入有误")# return -1def adminOption(self):inputAdmin = input("请输入管理员账号:")if self.admin != inputAdmin:print("输入有误")return -1inputPasswd = input("请输入管理员密码:")if self.passwd != inputPasswd:print("输入有误")return -1#能执行到这里说明账号密码正确print("操作成功!请稍后。。。")time.sleep(2)return 0def sysFunctionView(self):print("************************************************")print("* 开户(1) 查询(2) *")print("* 取款(3) 存款(4) *")print("* 转账(5) 改密(6) *")print("* 锁定(7) 解锁(8) *")print("* 补卡(9) 销户(0) *")print("* 退出T *")print("************************************************")