APO-1 Final build for meetings #1
This commit is contained in:
parent
cb8758d602
commit
e64c2db473
39
init.py
39
init.py
@ -1,13 +1,30 @@
|
|||||||
cards = [
|
from src.modules.Card import Card
|
||||||
{"number": "1111222233334444", "type": "Credit", "pin": "1234"},
|
from src.modules.Account import Account
|
||||||
{"number": "2222333344445555", "type": "Prepaid", "pin": "2345"},
|
|
||||||
{"number": "3333444455556666", "type": "ATM", "pin": "3456"},
|
# This will immitate all bank accounts that exist
|
||||||
{"number": "444666", "type": "University ID", },
|
accounts = [
|
||||||
|
{"number": "0123456789", "name": "John", "surname": "Doe", "credit": 50000},
|
||||||
|
{"number": "0122222222", "name": "John", "surname": "Two", "credit": 50},
|
||||||
|
{"number": "0123444444", "name": "John", "surname": "Digit", "credit": 150},
|
||||||
|
{"number": "0111111111", "name": "John", "surname": "Button", "credit": 400},
|
||||||
]
|
]
|
||||||
|
|
||||||
accounts = [
|
# This will immitate banks API
|
||||||
{},
|
bank = {}
|
||||||
{},
|
|
||||||
{},
|
for account in accounts:
|
||||||
{},
|
bank[account["number"]] = Account(account["number"], account["name"], account["surname"], account["credit"])
|
||||||
]
|
|
||||||
|
#This will immitate all cards that exist
|
||||||
|
cardsInit = [
|
||||||
|
{"number": "1111222233334444", "type": "Credit", "pin": "1234", "account": bank["0123456789"]},
|
||||||
|
{"number": "2222333344445555", "type": "Prepaid", "pin": "2345", "account": bank["0122222222"]},
|
||||||
|
{"number": "3333444455556666", "type": "ATM", "pin": "3456", "account": bank["0123444444"]},
|
||||||
|
{"number": "444666", "type": "University ID", "pin": None, "account": None},
|
||||||
|
]
|
||||||
|
|
||||||
|
# This will immitate card providers API
|
||||||
|
cards = {}
|
||||||
|
|
||||||
|
for card in cardsInit:
|
||||||
|
cards[card["number"]] = Card(card["number"], card["pin"], card["type"], card["account"])
|
||||||
|
53
main.py
53
main.py
@ -1,10 +1,53 @@
|
|||||||
from src.tools.tools import *
|
from src.tools.tools import *
|
||||||
from src.modules.Card import Card
|
from init import *
|
||||||
from src.modules.Account import Acount
|
|
||||||
import init
|
|
||||||
|
|
||||||
|
mode = "running"
|
||||||
|
|
||||||
|
while mode != "exit":
|
||||||
|
input()
|
||||||
|
|
||||||
card = cards[int(input("Chose a card from 1 to " + str(len(cards)) + ": ")) - 1]
|
counter = 1
|
||||||
|
for card in cards:
|
||||||
|
print(str(counter) + ": " + card)
|
||||||
|
counter += 1
|
||||||
|
|
||||||
PrintCardInfo(Card(card["number"], card["pin"], card["type"]))
|
card = cards[input("Enter number of card you wish to use: ")]
|
||||||
|
|
||||||
|
if VerifyInvalidCard(card):
|
||||||
|
print("That is not a valid ATM card")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if VerifyOwner(card):
|
||||||
|
print("What do you want to do?")
|
||||||
|
print("1. Check your account")
|
||||||
|
print("2. Withdraw Money")
|
||||||
|
print("3. Deposit Money")
|
||||||
|
print("4. Add credits to your pre-paid phone card")
|
||||||
|
print("5. Transfer Money")
|
||||||
|
print("6. Exit")
|
||||||
|
|
||||||
|
operation = input()
|
||||||
|
|
||||||
|
if operation == "1":
|
||||||
|
CheckAccount(card.account)
|
||||||
|
elif operation == "2":
|
||||||
|
amount = int(input ("How much money do you want to withdraw?"))
|
||||||
|
WithdrawMoney(amount, card.account)
|
||||||
|
elif operation == "3":
|
||||||
|
notes = []
|
||||||
|
value = int(input("Value of the inserted note: "))
|
||||||
|
notes.append(value)
|
||||||
|
while value != 0:
|
||||||
|
value = int(input("Value of the next note (0 to exit): "))
|
||||||
|
notes.append(value)
|
||||||
|
DepositMoney(notes, card.account)
|
||||||
|
elif operation == "4":
|
||||||
|
operator = input("Enter name of your phone card operator: ")
|
||||||
|
amount = int(input("How much credits do you wish to add?"))
|
||||||
|
GeneratePrepaidPhoneCode(amount, operator, card.account)
|
||||||
|
elif operation == "5":
|
||||||
|
accountTo = input("Enter account number to which money should be transfered: ")
|
||||||
|
amount = int(input("How much money should be transfered?: "))
|
||||||
|
TransferMoney(card.account, bank[accountTo], amount)
|
||||||
|
elif operation == "6":
|
||||||
|
mode = "exit"
|
@ -1,10 +1,23 @@
|
|||||||
class Acount:
|
class Account:
|
||||||
def __init__(self, number, name, surname, credit):
|
def __init__(self, number, name, surname, credit):
|
||||||
self.number = number
|
self.number = number
|
||||||
self.name = name
|
self.name = name
|
||||||
self.surname = surname
|
self.surname = surname
|
||||||
self.credit = credit
|
self.credit = credit
|
||||||
self.cards = []
|
self.cards = []
|
||||||
|
self.acceptTransfers = True
|
||||||
|
|
||||||
def addCard(self, card):
|
def addCard(self, card):
|
||||||
self.cards.append(card)
|
self.cards.append(card)
|
||||||
|
|
||||||
|
def addCredit(self, amount):
|
||||||
|
self.credit += amount
|
||||||
|
|
||||||
|
def subCredit(self, amount):
|
||||||
|
self.credit -= amount
|
||||||
|
|
||||||
|
def allowTransfers(self):
|
||||||
|
self.acceptTransfers = True
|
||||||
|
|
||||||
|
def disallowTransfers(self):
|
||||||
|
self.acceptTransfers = False
|
@ -4,7 +4,10 @@ class Card:
|
|||||||
self.pin = pin
|
self.pin = pin
|
||||||
self.type = type
|
self.type = type
|
||||||
self.account = account
|
self.account = account
|
||||||
account.addCard(self)
|
if self.account:
|
||||||
|
account.addCard(self)
|
||||||
|
self.blocked = False
|
||||||
|
self.wrongCounter = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,6 +1,91 @@
|
|||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
def PrintCardInfo(card):
|
def PrintCardInfo(card):
|
||||||
print("Owner's Name: " + card.account.name)
|
print("Owner's Name: " + card.account.name)
|
||||||
print("Owner's Surname: " + card.account.surname)
|
print("Owner's Surname: " + card.account.surname)
|
||||||
print("Card's Number: " + card.number)
|
print("Card's Number: " + card.number)
|
||||||
print("Card's Type: " + card.type)
|
print("Card's Type: " + card.type)
|
||||||
print("Card's PIN: " + card.pin)
|
print("Card's PIN: " + card.pin)
|
||||||
|
|
||||||
|
def VerifyInvalidCard(card):
|
||||||
|
if card.type not in ["ATM", "Credit", "Prepaid"]:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def VerifyOwner(card):
|
||||||
|
inputPin = input("Enter PIN for this card, please: ")
|
||||||
|
if inputPin == card.pin:
|
||||||
|
card.wrongCounter = 0
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
card.wrongCounter += 1
|
||||||
|
if card.wrongCounter == 3:
|
||||||
|
card.wrongCounter = 0
|
||||||
|
card.blocked = True
|
||||||
|
print("You've entered wrong PIN three times. This card will be blocked.")
|
||||||
|
return False
|
||||||
|
continueAnswer = input("Do you want to try again? (Y/N): ")
|
||||||
|
if continueAnswer in ["Y", "y", "Yes", "yes"]:
|
||||||
|
VerifyOwner(card)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def WithdrawMoney(amount, account):
|
||||||
|
if amount > account.credit:
|
||||||
|
print("You dont't have enough money on your account")
|
||||||
|
return 0
|
||||||
|
if amount%10 != 0:
|
||||||
|
print("Enter multiple of 10")
|
||||||
|
return 0
|
||||||
|
account.subCredit(amount)
|
||||||
|
out = ""
|
||||||
|
while amount >= 200:
|
||||||
|
amount -= 200
|
||||||
|
out = out + "200 "
|
||||||
|
while amount >= 100:
|
||||||
|
amount -= 100
|
||||||
|
out = out + "100 "
|
||||||
|
while amount >= 50:
|
||||||
|
amount -= 50
|
||||||
|
out = out + "50 "
|
||||||
|
while amount >= 20:
|
||||||
|
amount -= 20
|
||||||
|
out = out + "20 "
|
||||||
|
while amount >= 10:
|
||||||
|
amount -= 10
|
||||||
|
out = out + "10 "
|
||||||
|
print (out)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def GeneratePrepaidPhoneCode(amount, operator, account):
|
||||||
|
if amount > account.credit:
|
||||||
|
print("You dont't have enough money on your account")
|
||||||
|
return 0
|
||||||
|
# print(operatorAPI(amount, operator))
|
||||||
|
print(''.join(random.choices(string.ascii_uppercase + string.digits, k=14)))
|
||||||
|
account.subCredit(amount)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def DepositMoney(notes, account):
|
||||||
|
amount = 0
|
||||||
|
for note in notes:
|
||||||
|
amount += int(note)
|
||||||
|
account.addCredit(amount)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def CheckAccount(account):
|
||||||
|
print("Stored money: " + str(account.credit))
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def TransferMoney(accountFrom, accountTo, amount):
|
||||||
|
if amount > accountFrom.credit:
|
||||||
|
print("You dont't have enough money on your account")
|
||||||
|
return 0
|
||||||
|
accountFrom.subCredit(amount)
|
||||||
|
accountTo.addCredit(amount)
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user