def createAccount(self, acct, bal): # this should return True if account create successful else false # Should be able to create savings and checking, but not loans # SHOULD THERE BE createLoan()? #TODO: CHECK FOR MIN BALANCES """ Summary line. Creates various accounts for the user Parameters ---------- acct: str account type as string either "Savings" or "Checking" bal: int account starting balance Returns ------- True if success False if else """ if self.__doesExist(acct): print("You already have an account of this type") return False if acct == "Savings" or acct == 0 and self.accounts["Savings"]: if bal < Savings.getMinBal(): print( "You must open an account with a balance greater than or equal to ${}" .format(Savings.getMinBal())) return False self.savings = Savings(bal) self.accounts["Savings"] = True return True elif acct == "Checking" or acct == 1 and self.account["Checking"]: if bal < Checking.getMinBal(): print( "You must open an account with a balance greater than or equal to ${}" .format(Checking.getMinBal())) return False self.checking = Checking(bal) self.accounts["Checking"] = True return True elif acct == "Cancel" or acct == "x" or acct == -1: print("Create cancelled") return False else: acctType = input( "Please enter account type (Savings, or Checking): ") return self.createAccount(acctType) return False
# -*- coding: utf-8 -*- from Savings import * from Loan import * from Calculator import * #from storage import * from Plot import * #Profar Loan og Savings: S1 = Savings('Ubersparnadur', 100000, 1.7, True, 12) S2 = Savings('Sparigris', 100000, 3.5, False, 3) L1 = Loan('Husnaedislan', 30000000, 1.3, 240, True) L2 = Loan('Yfirdrattur', 450000, 20, 6, False) print L1 print print L2 print S1 print '\nEf madur borgar 1000 kr inn a sparnadinn naestu 6 manudi ta verdur troun reikningsins naestu 12 manudi:' print S1.printProgression(1000, 6, 12) print '\nEf madur borgar 0 kr inn a sparnadinn naestu 6 manudi ta verdur troun reikningsins naestu 12 manudi:' print S1.printProgression(1000, 0, 12) print '\nMed tvi ad leggja 1000 kr inn a manudi inn ta geturdu tekid ut eftirfarandi upphaed eftir 12 manudi:' #Ath verdur ad haetta ad leggja inn svo binditimi klarist adur en tekid er ut print S1.saveforM(1000, 12) print '\nMed tvi ad leggja 1000 kr inn a manudi inn ta verdur stadan a reikningunum ordin haerri en 250.000 eftir:' print S1.saveuptoX(1000, 250000) print print S2 print '\nEf madur borgar 1000 kr inn a sparnadinn naestu 6 manudi ta verdur troun reikningsins naestu 12 manudi:' print S2.printProgression(1000, 6, 12) print '\nEf madur borgar 0 kr inn a sparnadinn naestu 6 manudi ta verdur troun reikningsins naestu 12 manudi:'
#Sæki upplýsingar um öll lán úr skránni loans.txt loans = storage.loadLoans(); #Vel hagkvæmasta lánið - í vinnslu #L = Calculator.compareAllLoans(loans, Man_sparn, Sparnadartimi); #print L; #Sæki upplýsingar um alla reikninga #accts = storage.loadSAccts() #Virkar ekki því það vantar skránna eins og er #Finn hvaða reikningur er hagkvæmastur fyrir notanda: #Nota bull reikning tímabundið Reikningur = Savings('Jonas', 1000, 5.5, 0, 0); #Vista þann reikning sem Savings hlutinn Reikningur #Finn hvað notandi er lengi að safna fyrir Sparnadarmarkmid m.v. Man_sparn lagt til hliðar á mánuði if ((not Sparnadarmarkmid == -1) and (not Man_sparn == -1)): m = Reikningur.saveuptoX(Man_sparn,Sparnadarmarkmid); print 'Það tekur þig ', m, ' mánuði að safna ', locale.currency(Sparnadarmarkmid, grouping = True), ' með því að leggja fyrir ', locale.currency(Man_sparn, grouping = True), ' á mánuði' ; #Birti hvað notandi nær að safna miklu á Sparnadartimi mánuðum m.v. Man_sparn lagt til hliðar á mánuði if ((not Sparnadartimi == -1) and (not Man_sparn == -1)): M = Reikningur.saveforM(Man_sparn, Sparnadartimi); #Ath: Notkunarskilyrði fallsins eru röng. Biður um Rauntölu en verður að vera heiltala fyrir seinni breytu. print 'Þú nærð að safna ', locale.currency(M, grouping = True), ' með því að leggja fyrir ', locale.currency(Man_sparn, grouping = True), ' á mánuði í ', Sparnadartimi, ' mánuði';
def testDatSavings2_UT06(self): S = Savings('Sparigrís', 1000, 12, False, 0) self.assertEqual(S.datSavings2(0,100,5,3,12)[1][3],1040) self.assertEqual(S.datSavings2(50,100,5,3,12)[1][6],1529) self.assertEqual(S.datSavings2(0,100,5,3,12)[1][11],1441)
def testDatSavings_UT05(self): S = Savings('Sparigrís', 1000, 12, False, 0) self.assertEqual(S.datSavings(100,5,12)[1][3],1450) self.assertEqual(S.datSavings(100,5,12)[1][6],1595) self.assertEqual(S.datSavings(100,5,12)[1][11],1670) self.assertEqual(S.datSavings(100,5,12)[0][6],7)
def testSaveuptoX_UT04(self): S = Savings('Bundinn 2', 1000, 12, False, 2) self.assertEqual(S.saveuptoX(100,1000),0) self.assertEqual(S.saveuptoX(100,1200),4) self.assertEqual(S.saveuptoX(100,2398),14)
def testSaveforM_UT03(self): S = Savings('Bundinn 2', 1000, 12, False, 2) self.assertEqual(S.saveforM(100,2),1000) self.assertEqual(S.saveforM(100,4),1200) self.assertEqual(S.saveforM(100,14),2398)
def testSProgression2_UT02(self): S = Savings('Sparigrís', 1000, 12, False, 0) self.assertEqual(S.progression2(0, 100, 5, 3, 12)[12],[1300,141]) self.assertEqual(S.progression2(50, 100, 5, 3, 12)[7],[1450,79]) self.assertEqual(S.progression2(0, 100, 5, 3, 12)[4],[1000,40])
def testSProgression_UT01(self): S = Savings('Sparigrís', 1000, 12, False, 0) self.assertEqual(S.progression(100, 5, 12)[12],[1500,170]) self.assertEqual(S.progression(100, 5, 12)[7],[1500,95]) self.assertEqual(S.progression(100, 5, 12)[4],[1400,50])
class Customer(Person): def __init__(self, name, birthdate, phoneNumber, address, ssn): """ Summary line. Initializing the variables. Parameters ---------- name: str name of the customer birthdate: str birthdate of the customer passed as MM/DD/YYYY phonenumber: int phonenumber of the customer address: str address of the customer ssn: int Social securtiy number of the customer Returns ------- Doesn't return anything """ Person.__init__(self, name, birthdate, phoneNumber, address) self.isMinor = True if self.getAge() < 18 else False self.ssn = ssn #What are we going to use this for? identifying loans? self.accounts = { "Savings": False, "Checking": False, "Loan": False } # this is just an easy way to keep track of what accounts are open def getInfo(self): """ Summary line. Returns customer info Parameters ---------- None Returns ------- Returns # of accounts open Initialized customer info Does NOT return balances - see checkBalance() """ exists = [] for account in self.accounts: if self.__doesExist(account): exists.append(account) return "Name: {}\nBirthdate: {}\nPhone Number: {}\nAddress: {}\nMinor: {}\nAccounts open:{}".format( self.name, self.birthdate, self.phoneNumber, self.address, self.isMinor, ", ".join(exists)) def __doesExist(self, acct): """ Summary: check for account existance Description: Checks the initialized self.accounts dictionary and returns wether an account exists or not Parameters _________ acct: str Account type either "Savings" or "Checking" or "Loan" Returns _______ Boolean Returns True if account exists False if account doesnt exist or doesnt match any keywords """ try: return self.accounts[acct] except KeyError: print("Non-Valid account type {}".format(acct)) return False def createAccount(self, acct, bal): # this should return True if account create successful else false # Should be able to create savings and checking, but not loans # SHOULD THERE BE createLoan()? #TODO: CHECK FOR MIN BALANCES """ Summary line. Creates various accounts for the user Parameters ---------- acct: str account type as string either "Savings" or "Checking" bal: int account starting balance Returns ------- True if success False if else """ if self.__doesExist(acct): print("You already have an account of this type") return False if acct == "Savings" or acct == 0 and self.accounts["Savings"]: if bal < Savings.getMinBal(): print( "You must open an account with a balance greater than or equal to ${}" .format(Savings.getMinBal())) return False self.savings = Savings(bal) self.accounts["Savings"] = True return True elif acct == "Checking" or acct == 1 and self.account["Checking"]: if bal < Checking.getMinBal(): print( "You must open an account with a balance greater than or equal to ${}" .format(Checking.getMinBal())) return False self.checking = Checking(bal) self.accounts["Checking"] = True return True elif acct == "Cancel" or acct == "x" or acct == -1: print("Create cancelled") return False else: acctType = input( "Please enter account type (Savings, or Checking): ") return self.createAccount(acctType) return False def checkBalance(self, acct=None): #TODO: return true and false and just print information since this is a interface class(it interfaces between classes """ Summary: Checks account balances and prints if they exist Description: Checks for account existance - if no accounts exists cancel or if the specific account doesnt exist cancel Parameters _________ acct: str Either "Checking", "Savings", or "Loan" if left empty the user is prompted Returns _______ Boolean True if account check succeeds false if not """ numAccts = 0 for account in self.accounts: if self.accounts[account]: numAccts += 1 if numAccts == 0: print("Please create an account first") return False if acct == "Cancel" or acct == "x" or acct == -1: print("Check cancelled") return False elif self.__doesExist( acct ): #use this method rather than just self.accounts[acct] to catch keyErrors if acct == "Savings": print("Your {} account balance is: {}".format( acct.lower(), self.savings.getBalance())) elif acct == "Checking": print("Your {} account balance is: {}".format( acct.lower(), self.checking.getBalance())) elif acct == "Loan": print("Your {} account balance is: {}".format( acct.lower(), self.loan.getBalance())) return True elif acct in self.accounts: print("Please create the {} account first".format(acct)) return False else: acct = input( "Please enter account type (Savings, Checking, or Loan): ") print(self.checkBalance(acct)) return False def askForLoan(self, managerId=0): #check for correct manager id before creating loan - or should this all be taken care of from the manager standpoint print("NOT YET IMPLEMENTED") def depositTo(self, acct, ammt): """ Summary: deposits to spefied account prints an error on fail Parameters _________ acct: str Account type either "Savings" or "Checking" ammt: int Ammount to be deposited to acct Returns _______ Boolean Returns True on success and False on fail """ if self.__doesExist(acct): if acct == "Savings": self.savings.deposit(ammt) return True elif acct == "Checking": self.checking.deposit(ammt) return True else: print("No account of {} type exists".format(acct)) return False def withdrawFrom(self, acct, ammt): """ Summary: Withdraw from account prints an error on fail Parameters _________ acct: str Account type either "Savings" or "Checking" ammt: int Ammount to withdraw from acct Returns _______ Bool Returns true on success false on fail """ if self.__doesExist(acct): if acct == "Savings": out = self.savings.withdraw(ammt) print(out) if isinstance(out, int): return True else: return False elif acct == "Checking": out = self.checking.withdraw(ammt) print(out) if isinstance(out, int): return True else: return False else: print("No account of {} type exists".format(acct)) return False def makePayment(self, ammt): #allows for making payments on loans ONLY print("NOT YET IMPLEMENTED")