简易ATM程序

#user

import pickle
import os
class User:
    def __init__(self,name,id,tel,card):
        self.name = name
        self.id = id
        self.tel = tel
        self.card = card
    @staticmethod
    def xieru(x):
        path =os.path.join(os.getcwd(),'a.db')
        f = open(path,'wb')
        pickle.dump(x,f)
        f.close()
    @staticmethod
    def duqu():
        path = os.path.join(os.getcwd(),'a.db')
        f = open(path,'rb')
        a = pickle.load(f)
        f.close()
        return a

#admin

class Admin:
    def __init__(self,name,passwd):
        self.name = name
        self.passwd = passwd

    def login(self):
        for i in range(3):
            name = input('输入管理员账号:')
            passwd = input('输入管理员密码:')
            if name == self.name and passwd == self.passwd :
                print('登陆成功!')
                return True
            else:
                print('登录失败!')

#card

class Card:
    def __init__(self,num,money,pwd):
        self.num = num
        self.money = money
        self.pwd = pwd
        self.clock = False

#ATM

from user import User
from card import Card
from admin import Admin
import random

class Atm:
    def __init__(self):
        self.user_dict = {}

    def welcome(self):
        print('*' * 30)
        print('*' + " " * 6 + '开户(1)' + '  ' + '查询(2)' + ' ' * 6 + '*')
        print("*" + " " * 6 + '取款(3)' + '  ' + '存款(4)' + ' ' * 6 + '*')
        print("*" + " " * 6 + '转账(5)' + '  ' + '改密(6)' + ' ' * 6 + '*')
        print("*" + " " * 6 + '锁定(7)' + '  ' + '解锁(8)' + ' ' * 6 + '*')
        print("*" + " " * 6 + '销户(9)' + '  ' + '退出(0)' + ' ' * 6 + '*')
        print('*' * 30)
    def mkcard(self):
        cardid = ''
        for i in range(6):
            a = str(random.randint(0,9))
            cardid += a
        return cardid

if __name__ == '__main__':

    atm = Atm()
    admin = Admin('admin','123456')


    if admin.login():
        try:
            atm.user_dict = User.duqu()
        except Exception as e:
            print(' ')
        while True:
            atm.welcome()
            print(atm.user_dict)
            choice = int(input('请输入想要执行的操作:'))
            if choice == 1:
                name = input('输入姓名:')
                cid = input('身份证号:')
                tel = input('手机号:')
                pwd1 = input('输入密码:')
                pwd2 = input('再次确认密码:')
                if pwd1 == pwd2 :
                    num = atm.mkcard()
                    money = int(input('请输入开户金额(>=10$):'))
                    if money < 10 :
                        print('金额太少,开户失败')
                        continue
                    card = Card(num,money,pwd2)
                    user = User(name,cid,tel,card)
                    atm.user_dict[num] = user
                    # User.xieru(fdy.user_dict)
                    print('开户成功,您的卡号为:%s 卡上余额%.2f:'%(num,money))
                else:
                    print('密码不一致,开户失败')


            elif choice == 2:
                num = input('请输入卡号:')
                if num in atm.user_dict:
                    user = atm.user_dict.get(num)
                    if user.card.clock == False:
                        for i in range(3):
                            pwd = input('请输入密码:')
                            if pwd == user.card.pwd:
                                print('卡号:%s 姓名:%s 手机号:%s 余额:%.2f¥'%
                                      (num,user.name,user.tel,user.card.money))
                                break
                            else:
                                print('密码错误!')
                        else:
                            print('密码错误三次,卡已被锁!')
                            user.card.clock = True

                            # '''此处切记要将字典信息再保存一遍'''
                            # User.xieru(fdy.user_dict)
                    else:
                        print('此卡已锁,请先解锁!')
                else:
                    print('卡号不存在!')
            elif choice == 3:
                num = input('请输入卡号:')
                if num in atm.user_dict:
                    user = atm.user_dict.get(num)
                    if user.card.clock == False:
                        for i in range(3):
                            pwd = input('请输入密码:')
                            if pwd == user.card.pwd:
                                qumoney = int(input('请输入取款金额:'))
                                if qumoney <= user.card.money:
                                    user.card.money-=qumoney
                                    # User.xieru(fdy.user_dict)
                                    print('取款成功!卡上余额:%.2f¥'%(user.card.money))
                                    break
                                else:
                                    print('余额不足!')
                                    break
                            else:
                                print('密码错误!')
                        else:
                            print('密码错误三次,卡已被锁!')
                            user.card.clock = True
                            # User.xieru(fdy.user_dict)
                    else:
                        print('此卡已锁,请先解锁!')
                else:
                    print('卡号不存在!')
            elif choice == 4:
                num = input('请输入卡号:')
                if num in atm.user_dict:
                    user = atm.user_dict.get(num)
                    if user.card.clock == False:
                        for i in range(3):
                            pwd = input('请输入密码:')
                            if pwd == user.card.pwd:
                                qumoney = float(input('请输入存款金额:'))
                                user.card.money += qumoney
                                # User.xieru(fdy.user_dict)
                                print('存款成功!卡上余额:%.2f¥'%(user.card.money))
                                break
                            else:
                                print('密码错误!')
                        else:
                            print('密码错误三次,卡已被锁!')
                            user.card.clock = True
                            # User.xieru(fdy.user_dict)
                    else:
                        print('此卡已锁,请先解锁!')
                else:
                    print('卡号不存在!')
            elif choice == 5:
                num = input('请输入卡号:')
                if num in atm.user_dict:
                    user = atm.user_dict.get(num)
                    if user.card.clock == False:
                        for i in range(3):
                            pwd = input('请输入密码:')
                            if pwd == user.card.pwd:
                                qumoney = float(input('请输入转账金额:'))
                                num1 = input('请输入对方卡号:')
                                if num1 in atm.user_dict:
                                    user1 = atm.user_dict.get(num1)
                                    if qumoney <= user.card.money:
                                        print('y:确认转账 n:取消转账')
                                        answer = input('')
                                        if answer == 'y':
                                            user.card.money-=qumoney
                                            user1.card.money+=qumoney
                                            # User.xieru(fdy.user_dict)
                                            print('转账成功!卡上余额:%.2f¥'%(user.card.money))
                                            break
                                        elif answer == 'n':
                                            print('已取消转账!')
                                            break
                                    else:
                                        print('金额不足!')
                                        break
                                else:
                                    print('对方卡号不存在!')
                                    break
                            else:
                                print('密码错误!')
                        else:
                            print('密码错误三次,卡已被锁!')
                            user.card.clock = True
                            # User.xieru(fdy.user_dict)
                    else:
                        print('此卡已锁,请先解锁!')
                else:
                    print('卡号不存在!')
            elif choice == 6:
                num = input('请输入卡号:')
                if num in atm.user_dict:
                    user = atm.user_dict.get(num)
                    if user.card.clock == False:
                        for i in range(3):
                            pwd = input('请输入密码:')
                            if pwd == user.card.pwd:
                                pwd1 = input('请输入新的密码:')
                                pwd2 = input('请再次输入新的密码:')
                                if pwd1 == pwd2 :
                                    user.card.pwd = pwd2
                                    # User.xieru(fdy.user_dict)
                                    print('密码修改成功!')
                                    break
                            else:
                                print('密码错误!')

                        else:
                            print('密码错误三次,卡已被锁!')
                            user.card.clock = True
                            # User.xieru(fdy.user_dict)
                    else:
                        print('此卡已锁,请先解锁!')
                else:
                    print('卡号不存在!')
            elif choice == 7:
                num = input('请输入卡号:')
                if num in atm.user_dict:
                    user = atm.user_dict.get(num)
                    pwd = input('请输入密码:')
                    if pwd == user.card.pwd:
                        user.card.clock = True
                        # User.xieru(fdy.user_dict)
                        print('卡已锁!')
                    else:
                        print('密码错误!')
                else:
                    print('卡号无效!')
            elif choice == 8:
                num = input('请输入卡号:')
                if num in atm.user_dict:
                    user = atm.user_dict.get(num)
                    pwd = input('请输入密码:')
                    if pwd == user.card.pwd:
                        user.card.clock = False
                        # User.xieru(fdy.user_dict)
                        print('卡已解锁!')
                    else:
                        print('密码错误!')
                else:
                    print('卡号无效!')
            elif choice == 9:
                num = input('请输入卡号:')
                if num in atm.user_dict:
                    user = atm.user_dict.get(num)
                    if user.card.clock == False:
                        for i in range(3):
                            pwd = input('请输入密码:')
                            if pwd == user.card.pwd:
                                print('确定要销户吗?')
                                answer = input('y/n:')
                                if answer == 'y':
                                    atm.user_dict.pop(num)
                                    print('销户成功!')
                                    User.xieru(atm.user_dict)
                                    break
                                else:
                                    print('已取消操作!')
                                    break
                            else:
                                print('密码错误!')
                        else:
                            print('密码错误三次,卡已被锁!')
                            user.card.clock = True
                            # User.xieru(fdy.user_dict)
                    else:
                        print('此卡已锁,请先解锁!')
                else:
                    print('卡号不存在!')
            elif choice == 0:
            	#程序正常退出保存数据(非正常退出则无法保存)
                User.xieru(atm.user_dict)
                break

  开户

简易ATM程序

  查询

简易ATM程序

  取款

简易ATM程序

  存款

简易ATM程序

  改密

简易ATM程序

  销户

简易ATM程序

个人小结

psp2.1 任务内容 计划完成需要的时间(min) 实际完成需要的时间(min)
Planning 计划 10 9
Estimate 估计这个任务需要多少时间,并规划大致工作步骤 10 7
Development 开发 140 120
Analysis 需求分析 12 5
Design Spec 生成设计文档 5 5
Design Review 设计复审 5 5
Coding Standard 代码规范 3 2
Design 具体设计 10 12
Coding 具体编码 36 21
Code Review 代码复审 5 7
Test 测试 10 15
Reporting 报告 9 6
Test Report 测试报告 3 2
Size Measurement 计算工作量 2 1
Postmortem & Process Improvement Plan 事后总结 3 3
上一篇:ATM系统和购物车系统


下一篇:ATM机系统1.0(函数、文件版)