Initial commit
This commit is contained in:
commit
0ab1c26e39
3
.idea/.gitignore
vendored
Normal file
3
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
1
.idea/.name
Normal file
1
.idea/.name
Normal file
@ -0,0 +1 @@
|
|||||||
|
bank
|
10
.idea/bank.iml
Normal file
10
.idea/bank.iml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
17
.idea/inspectionProfiles/Project_Default.xml
Normal file
17
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredErrors">
|
||||||
|
<list>
|
||||||
|
<option value="N802" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="SpellCheckingInspection" enabled="true" level="TYPO" enabled_by_default="true">
|
||||||
|
<option name="processCode" value="false" />
|
||||||
|
<option name="processLiterals" value="false" />
|
||||||
|
<option name="processComments" value="false" />
|
||||||
|
</inspection_tool>
|
||||||
|
</profile>
|
||||||
|
</component>
|
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
7
.idea/misc.xml
Normal file
7
.idea/misc.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="MarkdownSettingsMigration">
|
||||||
|
<option name="stateVersion" value="1" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (hangman)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/bank.iml" filepath="$PROJECT_DIR$/.idea/bank.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
79
Account.py
Normal file
79
Account.py
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
from datetime import date
|
||||||
|
|
||||||
|
from Operation import Operation
|
||||||
|
|
||||||
|
|
||||||
|
class Account:
|
||||||
|
_owner = None
|
||||||
|
_id = None
|
||||||
|
_balance = 0.0
|
||||||
|
_max_debit = 100.0
|
||||||
|
_operations = []
|
||||||
|
_currency = None
|
||||||
|
|
||||||
|
def __init__(self, currency, owner, id):
|
||||||
|
self.setCurrency(currency)
|
||||||
|
self.setOwner(owner)
|
||||||
|
self.setId(id)
|
||||||
|
|
||||||
|
def setOwner(self, owner):
|
||||||
|
self._owner = owner
|
||||||
|
|
||||||
|
def getOwner(self):
|
||||||
|
return self._owner
|
||||||
|
|
||||||
|
def setId(self, id):
|
||||||
|
self._id = id
|
||||||
|
|
||||||
|
def getId(self):
|
||||||
|
return self._id
|
||||||
|
|
||||||
|
def setCurrency(self, currency):
|
||||||
|
self._currency = currency
|
||||||
|
|
||||||
|
def getCurrency(self):
|
||||||
|
return self._currency
|
||||||
|
|
||||||
|
def getBalance(self):
|
||||||
|
return self._balance
|
||||||
|
|
||||||
|
def changeBalance(self, amount, ):
|
||||||
|
self.checkDebit(amount)
|
||||||
|
self.createOperation("wypłata" if amount < 0 else "wpłata", amount, )
|
||||||
|
self._balance += amount
|
||||||
|
|
||||||
|
def getDebit(self):
|
||||||
|
return self._max_debit
|
||||||
|
|
||||||
|
def checkDebit(self, amount):
|
||||||
|
if self.getBalance() + amount < -self.getDebit():
|
||||||
|
raise Exception("Debit exceeded!")
|
||||||
|
|
||||||
|
def addOperation(self, operation):
|
||||||
|
self._operations.append(operation)
|
||||||
|
|
||||||
|
def incomingTransfer(self, amount, sender, title='Work payment'):
|
||||||
|
self.createOperation('Incoming transfer', amount, sender, title)
|
||||||
|
|
||||||
|
def outgoingTransfer(self, amount, recipient, title='Money transfer'):
|
||||||
|
self.createOperation('Outgoing transfer', amount, recipient, title)
|
||||||
|
|
||||||
|
def withdraw(self, amount):
|
||||||
|
if abs(amount) > self.getBalance() + self.getDebit():
|
||||||
|
raise Exception("Not enough money!")
|
||||||
|
if abs(amount) > self.getBalance():
|
||||||
|
print("You're in debt!")
|
||||||
|
self.changeBalance(-amount)
|
||||||
|
print(f"Withdrawal successful, balance: {self.getBalance()} {self.getCurrency()}")
|
||||||
|
|
||||||
|
def deposit(self, amount):
|
||||||
|
if not (amount % 10):
|
||||||
|
raise Exception("Deposit must be a multiple of 10")
|
||||||
|
self.createOperation("Deposit", amount, self, "Deposit at an ATM")
|
||||||
|
|
||||||
|
def createOperation(self, type, amount, person, title):
|
||||||
|
operation = Operation(type, amount, person, title, date.today())
|
||||||
|
self.addOperation(operation)
|
||||||
|
|
||||||
|
def getOperations(self):
|
||||||
|
return self._operations
|
53
Bank.py
Normal file
53
Bank.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
class Bank:
|
||||||
|
_accounts = []
|
||||||
|
_peopleID = {
|
||||||
|
"people": [],
|
||||||
|
"bankers": []
|
||||||
|
}
|
||||||
|
_name = None
|
||||||
|
_capital = None
|
||||||
|
|
||||||
|
def __init__(self, name):
|
||||||
|
self.setBankName(name)
|
||||||
|
self._capital = None
|
||||||
|
|
||||||
|
def setBankName(self, name):
|
||||||
|
self._name = name
|
||||||
|
|
||||||
|
def getBankName(self):
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
def setCapital(self, value):
|
||||||
|
self._capital = value
|
||||||
|
|
||||||
|
def getCapital(self):
|
||||||
|
return self._capital
|
||||||
|
|
||||||
|
def changeCapital(self, value):
|
||||||
|
self.getCapital() + value
|
||||||
|
|
||||||
|
def getIds(self):
|
||||||
|
return self._peopleID
|
||||||
|
|
||||||
|
def addId(self, person):
|
||||||
|
self._peopleID["people"].append(person)
|
||||||
|
|
||||||
|
def deleteId(self, id):
|
||||||
|
self.getIds()["people"].remove(id)
|
||||||
|
|
||||||
|
def addAccount(self, account, id):
|
||||||
|
self.addId(id)
|
||||||
|
self._accounts.append(account)
|
||||||
|
|
||||||
|
def getAccounts(self):
|
||||||
|
return self._accounts
|
||||||
|
|
||||||
|
def deleteAccount(self, account):
|
||||||
|
self.deleteId(account.getID())
|
||||||
|
account.getOwner().deleteAccount(account)
|
||||||
|
self.changeCapital(-account.getBalance())
|
||||||
|
self._accounts.remove(account)
|
||||||
|
|
||||||
|
def _hireBanker(self, banker):
|
||||||
|
banker.setBank(self)
|
||||||
|
self._peopleID["bankers"].append(banker)
|
29
Banker.py
Normal file
29
Banker.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
from Account import Account
|
||||||
|
from Person import Person
|
||||||
|
|
||||||
|
|
||||||
|
class Banker(Person):
|
||||||
|
_bank = None
|
||||||
|
|
||||||
|
def __init__(self, name, surname, currency):
|
||||||
|
super().__init__(name, surname, currency)
|
||||||
|
|
||||||
|
def setBank(self, bank):
|
||||||
|
self._bank = bank
|
||||||
|
|
||||||
|
def getBank(self):
|
||||||
|
return self._bank
|
||||||
|
|
||||||
|
def openAccount(self, person):
|
||||||
|
newID = random.randint(1, 999)
|
||||||
|
while newID in self.getBank().getIds():
|
||||||
|
newID = random.randint(1, 999)
|
||||||
|
person.addAccount(self.getBank().getBankName(), newID)
|
||||||
|
account = Account(person.getCurrency(), person, newID)
|
||||||
|
self.getBank().addAccount(account, newID)
|
||||||
|
return account
|
||||||
|
|
||||||
|
def closeAccount(self, account):
|
||||||
|
self.getBank().deleteAccount(account)
|
18
Boss.py
Normal file
18
Boss.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from Person import Person
|
||||||
|
|
||||||
|
|
||||||
|
class Boss(Person):
|
||||||
|
_bank = None
|
||||||
|
|
||||||
|
def __init__(self, name, surname, currency, bank):
|
||||||
|
super().__init__(name, surname, currency)
|
||||||
|
self.setBank(bank)
|
||||||
|
|
||||||
|
def getBank(self):
|
||||||
|
return self._bank
|
||||||
|
|
||||||
|
def setBank(self, value):
|
||||||
|
self._bank = value
|
||||||
|
|
||||||
|
def hireBanker(self, banker):
|
||||||
|
self.getBank()._hireBanker(banker)
|
46
Operation.py
Normal file
46
Operation.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
class Operation:
|
||||||
|
_operationTypes = None
|
||||||
|
_amount = None
|
||||||
|
_person = None
|
||||||
|
_title = None
|
||||||
|
_date = None
|
||||||
|
|
||||||
|
def __init__(self, type, amount, person, title, date):
|
||||||
|
self.setOperationType(type)
|
||||||
|
self.setAmount(amount)
|
||||||
|
self.setPerson(person)
|
||||||
|
self.setTitle(title)
|
||||||
|
self.setDate(date)
|
||||||
|
|
||||||
|
def getDate(self):
|
||||||
|
return self._date
|
||||||
|
|
||||||
|
def setDate(self, value):
|
||||||
|
self._date = value
|
||||||
|
|
||||||
|
def getTitle(self):
|
||||||
|
return self._title
|
||||||
|
|
||||||
|
def setTitle(self, title):
|
||||||
|
self._title = title
|
||||||
|
|
||||||
|
def getPerson(self):
|
||||||
|
return self._person
|
||||||
|
|
||||||
|
def setPerson(self, value):
|
||||||
|
self._person = value
|
||||||
|
|
||||||
|
def getOperationType(self):
|
||||||
|
return self._operationTypes
|
||||||
|
|
||||||
|
def setOperationType(self, value):
|
||||||
|
self._operationTypes = value
|
||||||
|
|
||||||
|
def getAmount(self):
|
||||||
|
return self._amount
|
||||||
|
|
||||||
|
def setAmount(self, value):
|
||||||
|
self._amount = value
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"Operation type: {self.getOperationType()}\nAmount: {self.getAmount()}\nAccount: {self.getPerson()}, \nDate: {self.getDate()}"
|
51
Person.py
Normal file
51
Person.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
class Person:
|
||||||
|
_name = None
|
||||||
|
_surname = None
|
||||||
|
_accounts = []
|
||||||
|
_currency = None
|
||||||
|
|
||||||
|
def __init__(self, name, surname, currency):
|
||||||
|
self.setName(name)
|
||||||
|
self.setSurname(surname)
|
||||||
|
self.setCurrency(currency)
|
||||||
|
|
||||||
|
def setName(self, name):
|
||||||
|
self._name = self._validateInput(name)
|
||||||
|
|
||||||
|
def getName(self):
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
def setSurname(self, surname):
|
||||||
|
self._surname = self._validateInput(surname)
|
||||||
|
|
||||||
|
def getSurname(self):
|
||||||
|
return self._surname
|
||||||
|
|
||||||
|
def addAccount(self, bank, id):
|
||||||
|
self._accounts.append((bank, id))
|
||||||
|
|
||||||
|
def getAccounts(self):
|
||||||
|
return self._accounts
|
||||||
|
|
||||||
|
def deleteAccount(self, account):
|
||||||
|
self.getAccounts().remove(account)
|
||||||
|
|
||||||
|
def getFullName(self):
|
||||||
|
return f"{self._name} {self._surname}"
|
||||||
|
|
||||||
|
def setCurrency(self, currency):
|
||||||
|
self._currency = currency
|
||||||
|
|
||||||
|
def getCurrency(self):
|
||||||
|
return self._currency
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _validateInput(input_value):
|
||||||
|
flag = re.search("^[a-zA-ZżźćńółęąśŻŹĆĄŚĘŁÓŃ]+$", input_value)
|
||||||
|
if flag:
|
||||||
|
return input_value.capitalize()
|
||||||
|
else:
|
||||||
|
raise Exception("Incorrect input!")
|
22
main.py
Normal file
22
main.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from Boss import Boss
|
||||||
|
from Bank import Bank
|
||||||
|
from Banker import Banker
|
||||||
|
from Person import Person
|
||||||
|
|
||||||
|
mbank = Bank('mBank')
|
||||||
|
ludzik = Person('adam', "KOWALSKI", 'ZŁ')
|
||||||
|
czlowiek = Person('jan', 'nowak', 'ZŁ')
|
||||||
|
kierwonik = Banker('bożena', 'nowak', 'ZŁ')
|
||||||
|
admin = Boss('wojciech', 'grzybowski', 'ZŁ', mbank)
|
||||||
|
|
||||||
|
admin.hireBanker(kierwonik)
|
||||||
|
konta = kierwonik.getBank().getAccounts()
|
||||||
|
print(konta)
|
||||||
|
czlowiek_konto = kierwonik.openAccount(czlowiek)
|
||||||
|
czlowiek_konto.changeBalance(10)
|
||||||
|
print([konto.getId() for konto in konta])
|
||||||
|
kierwonik.openAccount(ludzik)
|
||||||
|
print([konto.getOwner().getFullName() for konto in konta])
|
||||||
|
for konto in konta:
|
||||||
|
konto.changeBalance(-101)
|
||||||
|
print([konto.getBalance() for konto in konta])
|
Loading…
Reference in New Issue
Block a user