Merge pull request 'APO-1 merge to master' (#1) from APO-1 into master
Reviewed-on: #1
This commit is contained in:
commit
37fb598867
50
.gitignore
vendored
Normal file
50
.gitignore
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
bin/
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
.tox/
|
||||
.coverage
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
|
||||
# Mr Developer
|
||||
.mr.developer.cfg
|
||||
.project
|
||||
.pydevproject
|
||||
|
||||
# Rope
|
||||
.ropeproject
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
*.pot
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
30
init.py
Normal file
30
init.py
Normal file
@ -0,0 +1,30 @@
|
||||
from src.modules.Card import Card
|
||||
from src.modules.Account import Account
|
||||
|
||||
# This will immitate all bank accounts that exist
|
||||
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},
|
||||
]
|
||||
|
||||
# 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"])
|
54
main.py
54
main.py
@ -1 +1,53 @@
|
||||
print("It's alive!")
|
||||
from src.tools.tools import *
|
||||
from init import *
|
||||
|
||||
mode = "running"
|
||||
|
||||
while mode != "exit":
|
||||
input()
|
||||
|
||||
counter = 1
|
||||
for card in cards:
|
||||
print(str(counter) + ": " + card)
|
||||
counter += 1
|
||||
|
||||
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"
|
23
src/modules/Account.py
Normal file
23
src/modules/Account.py
Normal file
@ -0,0 +1,23 @@
|
||||
class Account:
|
||||
def __init__(self, number, name, surname, credit):
|
||||
self.number = number
|
||||
self.name = name
|
||||
self.surname = surname
|
||||
self.credit = credit
|
||||
self.cards = []
|
||||
self.acceptTransfers = True
|
||||
|
||||
def addCard(self, 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
|
13
src/modules/Card.py
Normal file
13
src/modules/Card.py
Normal file
@ -0,0 +1,13 @@
|
||||
class Card:
|
||||
def __init__(self, number, pin, type, account):
|
||||
self.number = number
|
||||
self.pin = pin
|
||||
self.type = type
|
||||
self.account = account
|
||||
if self.account:
|
||||
account.addCard(self)
|
||||
self.blocked = False
|
||||
self.wrongCounter = 0
|
||||
|
||||
|
||||
|
91
src/tools/tools.py
Normal file
91
src/tools/tools.py
Normal file
@ -0,0 +1,91 @@
|
||||
import random
|
||||
import string
|
||||
|
||||
def PrintCardInfo(card):
|
||||
print("Owner's Name: " + card.account.name)
|
||||
print("Owner's Surname: " + card.account.surname)
|
||||
print("Card's Number: " + card.number)
|
||||
print("Card's Type: " + card.type)
|
||||
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