From 0ab1c26e399b135551cff7ea6038fc2b5ee831e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=A1=E1=B4=8F=E1=B4=8A=E1=B4=84=C9=AA=E1=B4=87?= =?UTF-8?q?=E1=B4=84=CA=9C=20=C9=A2=CA=80=E1=B4=A2=CA=8F=CA=99=E1=B4=8F?= =?UTF-8?q?=E1=B4=A1=EA=9C=B1=E1=B4=8B=C9=AA?= Date: Tue, 9 May 2023 16:47:40 +0200 Subject: [PATCH] Initial commit --- .idea/.gitignore | 3 + .idea/.name | 1 + .idea/bank.iml | 10 +++ .idea/inspectionProfiles/Project_Default.xml | 17 ++++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/misc.xml | 7 ++ .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 ++ Account.py | 79 +++++++++++++++++++ Bank.py | 53 +++++++++++++ Banker.py | 29 +++++++ Boss.py | 18 +++++ Operation.py | 46 +++++++++++ Person.py | 51 ++++++++++++ main.py | 22 ++++++ 15 files changed, 356 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/bank.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Account.py create mode 100644 Bank.py create mode 100644 Banker.py create mode 100644 Boss.py create mode 100644 Operation.py create mode 100644 Person.py create mode 100644 main.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..35550bb --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +bank \ No newline at end of file diff --git a/.idea/bank.iml b/.idea/bank.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/.idea/bank.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..ece4fda --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,17 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..cc0ed16 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..290e587 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Account.py b/Account.py new file mode 100644 index 0000000..00ca2e7 --- /dev/null +++ b/Account.py @@ -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 diff --git a/Bank.py b/Bank.py new file mode 100644 index 0000000..687e0b3 --- /dev/null +++ b/Bank.py @@ -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) diff --git a/Banker.py b/Banker.py new file mode 100644 index 0000000..a3488a3 --- /dev/null +++ b/Banker.py @@ -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) diff --git a/Boss.py b/Boss.py new file mode 100644 index 0000000..46e9c99 --- /dev/null +++ b/Boss.py @@ -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) \ No newline at end of file diff --git a/Operation.py b/Operation.py new file mode 100644 index 0000000..568be41 --- /dev/null +++ b/Operation.py @@ -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()}" diff --git a/Person.py b/Person.py new file mode 100644 index 0000000..fcf9d41 --- /dev/null +++ b/Person.py @@ -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!") diff --git a/main.py b/main.py new file mode 100644 index 0000000..32fb546 --- /dev/null +++ b/main.py @@ -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]) \ No newline at end of file