列出對象及屬性名稱行為...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("************************************************")
?
?
?
?
?
?