def register(self, clientData, current=None): if any([clientData.id == acc['account'].get_id() for acc in account_table]): raise Bank.AccountAlreadyExistsException('Account already exists!') account_type = Bank.AccountType.Premium if clientData.income >= 1000 else Bank.AccountType.Standard account_pwd = '123' if account_type == Bank.AccountType.Premium: new_account = PremiumAccountI(clientData, account_type, account_pwd) identity = Ice.stringToIdentity("%s/%s" % ('premium', clientData.id)) proxy = Bank.PremiumAccountPrx.uncheckedCast(current.adapter.add(new_account, identity)) else: new_account = AccountI(clientData, account_type, account_pwd) identity = Ice.stringToIdentity("%s/%s" % ('standard', clientData.id)) proxy = Bank.AccountPrx.uncheckedCast(current.adapter.add(new_account, identity)) account_obj = { 'account': new_account, 'proxy': proxy } account_table.append(account_obj) print(account_table) return Bank.RegistrationInfo(account_type, account_pwd)
def createAccount(self, name, surname, threshold, id, context=None): if self.user_already_exists(id): raise Bank.UserAlreadyExists() if threshold > _premium_account_threshold: is_premium = True else: is_premium = False key = self.generate_random_string() new_user_info = {'id': id, 'name': name, 'surname': surname, 'is_premium': is_premium, 'has_loan': False, 'loan_return_native': 0.0, 'loan_return_foregin': 0.0, 'key': key, 'funds': {}} for currency in self.supported_currencies: new_user_info['funds'][str(Bank.Currency.valueOf(currency))] = 0 self.users.insert(new_user_info) registration_info = Bank.RegistrationInfo() self.bank_server.add_account_servant(str(id)) registration_info.key = key registration_info.isPremium = is_premium return registration_info
def setup(self): checking_account = CheckingAccount(G.player_initial_money, self.env) # a checking acount saving_account = SavingAccount(0, self.env) # a saving account self.player.set_bank_account( checking_account, saving_account) #give the above accounts to the player self.bank = Bank(self.player) #set up the bank
def __init__(self): self.players = [] self.currentPlayer = None self.board = Board() self.chancePile = ChanceCards() self.communityPile = CommunityCards() self.dice = TwoDice() self.bank = Bank()
class Manager: def __init__(self): self.bank = Bank() self.listCustomer = [] def addCustomer(self, id): customer = Customer(self.bank, id) self.bank.addCustomer(customer.id) self.listCustomer.append(customer)
def login(self, id, context=None): user = Query() user = self.users.search(user.id == id) if user == []: raise Bank.IncorrectCredentials() if user[0]['key'] != context.ctx['key']: raise Bank.IncorrectCredentials() self.bank_server.add_account_servant(str(id))
def takeALoan(self, pesel, currency, amount, current=None): curr = str(currency) if curr not in self.currencies(): raise Bank.LoanRejectionError('Invalid loan currency.') elif amount <= 0: raise Bank.LoanRejectionError('Invalid loan amount. Must be > 0.') in_pln = amount * self.current_ratio_handler(curr) print('Loan Offer: { ' + self.pesel + ', ' + curr + ', ' + str(amount), ', (PLN) ' + str(in_pln)) return Bank.LoanOffer(currency=currency, amountInPLN=in_pln, amount=amount)
def setPeriod(param): currency_type = param[0] cost = float(param[1]) p = input("write start date of your loan like January 2, 2010") start = p p = input("write end date of your loan like January 2, 2010") end = p return Bank.Credit(start, end, Bank.Cost(currencyToEnum(currency_type), cost))
def signUp(self, pesel, name, surname, income, current=None): print('Registration requested by: ' + str(pesel)) if any([pesel == account.pesel for account in accounts]): raise Bank.AccountException('Already signed up!') account = Bank.Account( pesel, name, surname, income, Bank.AccountType.PREMIUM if income >= premiumThreshold else Bank.AccountType.STANDARD, getNewPassword()) accounts.append(account) return account.password
def getAccountInfo(self, context=None): if not self.ok_credentials(context.ctx['id'], context.ctx['key']): raise Bank.IncorrectCredentials() account_info = Bank.AccountInfo() account_info.isPremium = bool(self.user[0]['is_premium']) account_info.hasLoan = False # account_info.loanInfo = account_info.funds = {} funds = self.user[0]['funds'] for (k, v) in funds.items(): new_key = map_currency(k) account_info.funds[new_key] = v return account_info
def __init__(self): self.players = [] self.currentPlayer = None self.board = Board() self.chancePile = ChanceCards() self.communityPile = CommunityCards() self.dice = TwoDice() self.bank = Bank() """Instance variables for the Controller""" self.gameMessages = None self.controllerInput = None self.functionCallName = None self.supportingData = None
def main(): myBank = Bank("TD Bank") print(myBank) print("total funds: " + str(myBank.getMoneyInBank())) myBank.depositIntoAccount myBank.depositIntoAccount myBank.withdrawFromAccount myBank.withdrawFromAccount print(myBank) print("total funds: " + str(myBank.getMoneyInBank()))
def getState(self, current=None): print('Account state requested by: ' + current.ctx['pesel']) try: account = checkSignIn(int(current.ctx['pesel']), current.ctx['password']) if not account: raise Bank.AccountException( 'Please provide correct login info') else: return Bank.Account(account.pesel, account.name, account.surname, account.income, account.type, account.password) except ValueError: raise Bank.AccountException('Please provide correct arguments')
def realitza_pagament(Usuario): pagament_correcte = B.Bank() confirm = pagament_correcte.do_payment(Usuario, Usuario.Pagament) #pagament_correcte = True pagamentOk = False if (confirm == False): # Reintentamos confirmar la reserva de vuelos... suponemos que no confirmacion = 1 while (confirmacion <= 3): confirm = pagament_correcte.do_payment(Usuario, Usuario.Pagament) #pagament_correcte=True if (confirm): pagamentOk = True break else: confirmacion = confirmacion + 1 if (pagamentOk == False): print( "Ha habido un problema durante el proceso de confirmacion del pagament, no se ha efectuado ningun cargo" ) else: pagamentOk = True return pagamentOk #TRUE OR FALSE
def testAddFundsInt(self): testBank = Bank("Test Bank") testUser = User(testBank, "username", "pass", 10) testUser.login("username", "pass") testAccount = Account(testUser, "account1") testAccount.addFunds(33) self.assertEqual(testAccount.getFunds(), 33)
def insertMoney(self, funds, context=None): if not self.ok_credentials(context.ctx['id'], context.ctx['key']): raise Bank.IncorrectCredentials() user_funds = self.user[0]['funds'] for (k, v) in funds.items(): user_funds[str(k)] += v self.db.update(set('funds', user_funds), self.user)
def new_account(param, account_factory): name = param[0] surname = param[1] pesel = param[2] income = float(param[3]) account_factory.crete(Bank.Person(name, surname, pesel), income) return login(pesel)
def add_user(self, pesel): if self.users.__contains__(pesel): raise Bank.UserAlreadyExsistsError() else: password = ''.join( random.choices(string.ascii_uppercase + string.digits, k=PASSWD_LEN)) self.users[pesel] = password return password
def getLoan(self, pin, password, howMuch, currency, current=None): acc = self.login(pin, password) if acc is None: raise Bank.LoginException('Wrong pin or password') if acc.type is not Bank.AccountType.PREMIUM: return Bank.LoanInfo(False, 0) isGranted = True cost = None for curr in currencyTable: if curr[0] == currency: cost = howMuch * curr[1] break if cost == None: raise Bank.CurrencyException('Wrong type of currency') acc.grantMoney(cost) return Bank.LoanInfo(isGranted, cost)
def __init__(self): self.bank = Bank.Bank() self.inventory = Inventory.Inventory() self.dayCounter = 0 self.servedCustomers = 0 self.satisfiedCustomers = 0 self.popularity = 0 self.cost = 0
def getFromEnum(currency): if currency == 'PLN': return Bank.Currency.PLN elif currency == 'USD': return Bank.Currency.USD elif currency == 'EURO': return Bank.Currency.EURO else: raise Bank.AccountException('Provide a correct currency')
def requestLoan(self, currency, amount, num_of_months, context=None): if not self.ok_credentials(context.ctx['id'], context.ctx['key']): raise Bank.IncorrectCredentials() if not self.user[0]['is_premium'] or self.user[0]['has_loan']: raise Bank.LoanNotAllowed() rates = self.exchange_client.get_exchange_rate() return_amount = amount * 1.3 return_amount_in_native = return_amount / rates[currency] self.user[0]['has_loan'] = True self.user[0]['loan_return_native'] = return_amount_in_native self.user[0]['loan_return_foreign'] = return_amount loan_info = Bank.LoanInfo() loan_info.amountInNativeCurrency = return_amount_in_native loan_info.amountInForeignCurrency = return_amount return loan_info
def create(self, name: str, pesel: str, monthlyIncome: float, current): accountType = Bank.AccountType.STANDARD if monthlyIncome <= 1000 else Bank.AccountType.PREMIUM password = ''.join(choices(string.digits + string.ascii_lowercase, k=4)) if accountType == Bank.AccountType.STANDARD: account = Account(name, pesel, monthlyIncome, password) else: account = PremiumAccount(name, pesel, monthlyIncome, password) current.adapter.add(account, Ice.stringToIdentity(str(pesel))) current.adapter.activate() return Bank.Confirmation(accountType, password)
def login(self, credentials, current=None): creds = Bank.UserCredentials(credentials).pesel self.user_manager.verify_credentials(creds.pesel, creds.password) acc_type = self.accounts[creds.pesel]._get_type() base = current.adapter.createProxy( Ice.stringToIdentity(creds.pesel + str(acc_type))) if acc_type == Bank.AccountType.STANDARD: return Bank.AccountPrx.uncheckedCast(base) else: return Bank.PremiumAccountPrx.uncheckedCast(base)
def login(self, current=None): if not current.ctx: raise Bank.InvalidCredentialsException('Specify login and password!') id = current.ctx['id'] pwd = current.ctx['pwd'] account = None for acc in account_table: if acc['account'].get_id() == id: if acc['account'].get_pwd() == pwd: account = acc['proxy'] else: raise Bank.InvalidCredentialsException('Invalid password!') if account is None: raise Bank.InvalidCredentialsException('Account with that id does not exist!') return account
def createAccount(self, firstName, lastName, pin, income, current=None): if any([pin == acc.getPin() for acc in accountTable]): raise Bank.AccountException( 'Account with Personal Identity Number like that already exists!' ) if (income >= 5000): newType = Bank.AccountType.PREMIUM else: newType = Bank.AccountType.STANDARD newPassword = "******" + str(random.randrange(1, 100)) newAccount = Account( { 'firstName': firstName, 'lastName': lastName, 'pin': pin, 'income': income }, newPassword, newType, 0) accountTable.append(newAccount) return Bank.RegistrationInfo(newPassword, newType)
def getLoan(self, amount, currency, length, current=None): if not current.ctx or current.ctx['id'] != self.get_id() or current.ctx['pwd'] != self.get_pwd(): raise Bank.InvalidCredentialsException('Invalid credentials!') currency = str.upper(str(currency)) if currency not in list(currency_table.keys()): raise Bank.InvalidCredentialsException('Bank does not support requested currency!') loan = amount * currency_table[currency] self.funds += loan self.loan_history.append({ 'currency': str(currency), 'amount': str(amount), 'length': str(length) }) print(self.loan_history) return loan
def main(): # We create the classes savings_account = Bank.SavingsAccount(100) checking_account = Bank.CheckingAccount(500) # The current balance of each class is shown print("Savings account: $", savings_account.get_balance()) print("Checking account: $", checking_account.get_balance()) print("\n") print("Amount to transfer: $120") # Using the savings_account we call the transfer method and add the checking_account # to validate if it's possible prior to moving the money savings_account.transfer(checking_account, 120) print("\n") # The new balance of each account is printed print("Savings account: $", savings_account.get_balance()) print("Checking account: $", checking_account.get_balance())
def main(): # 欢迎页面 AdminView.printWelcomeView() # 进入登陆页面 if AdminView.checkUserAndPassword() == -1: return -1 # 获取用户信息:通过本地文件读取已存在用户列表 # allUser.txt:存储用户信息的文件 # 假设用户数量为空 allUser = {} if os.path.getsize("allUser.txt") > 0: with open("allUser.txt", "rb") as f1: # 已经存在用户 allUser = pickle.load(f1) print(allUser) # 银行的对象只有一个 bank = Bank.Bank(allUser=allUser) # 进入主程序页面 while True: time.sleep(1) AdminView.mainFunctionView() checkFunc = input("请按照数字输入选择的功能") if checkFunc == "1": bank.createUser() elif checkFunc == "2": bank.seachUser() elif checkFunc == "3": bank.getMoney() elif checkFunc == "4": bank.saveMoney() elif checkFunc == "5": bank.changePassword() elif checkFunc == "6": bank.createOtherCard() elif checkFunc == "7": bank.lockedCard() elif checkFunc == "8": bank.unlockedCard() elif checkFunc == "9": bank.cancelUser() elif checkFunc == "z": bank.transferMoney() elif checkFunc == "0": # 存入或更新数据 with open("allUser.txt", "wb") as f1: pickle.dump(bank.allUser, f1) return 0 else: print("输入错误,请确认后重新输入")
def requestLoan(self, currency, loanAmount, months, current=None): print('Login requested by: ' + current.ctx['pesel']) account = checkSignIn(int(current.ctx['pesel']), current.ctx['password']) if not account: raise Bank.AccountException('Please provide correct login info') else: if account.type == Bank.AccountType.STANDARD: raise Bank.AccountException( 'Requesting a loan requires a PREMIUM account!') else: try: foreignCurrencyValue = next( currencyIter['value'] for currencyIter in currencyTable if currencyIter['type'] == currency.name) return Bank.LoanRates( loanAmount * loanInterest, loanAmount * loanInterest * foreignCurrencyValue) except StopIteration: raise Bank.AccountException( 'Please provide a valid currency!')