class SavingsAccountTestCase(TestCase): def setUp(self): self.holder = 'John' self.account_number = 12345 self.starting_balance = 1500 self.interest_rate = 0.01 self.account = SavingsAccount(self.holder, self.account_number, self.starting_balance, self.interest_rate) def test_create_account(self): self.assertEqual(self.holder, self.account.get_holder()) self.assertEqual(self.account_number, self.account.get_account_number()) self.assertEqual(self.starting_balance, self.account.get_balance()) self.assertEqual(self.interest_rate, self.account.get_interest_rate()) @unittest.skipIf(not sys.platform.startswith('darwin'), 'Only run on mac') def test_001_mac(self): self.fail('You are on a mac') pass @unittest.skipIf(not sys.platform.startswith('linux'), 'Only run on linux') def test_001_linux(self): pass def test_interest_rate_works(self): a = self.account m_rate = self.interest_rate / 12 added = self.starting_balance * m_rate self.assertEqual(self.starting_balance, a.get_balance()) self.assertEqual(added, a.add_monthly_interest()) self.assertEqual(self.starting_balance + added, a.get_balance())
def test_create_account_interest_rate(self): name = 'Jaime' number = 6732 balance = 10000 interest = 0.01 a = SavingsAccount(name, number, balance, interest) self.assertEqual(interest, a.get_interest_rate())
def setUp(self): self.holder = 'John' self.account_number = 12345 self.starting_balance = 1500 self.interest_rate = 0.01 self.account = SavingsAccount(self.holder, self.account_number, self.starting_balance, self.interest_rate)
def test_compound_interest(self): name = 'Jaime' number = 6732 balance = 10000 interest = 0.01 a = SavingsAccount(name, number, balance, interest) m_rate = interest / 12 added = balance * m_rate new_balance = added + balance self.assertEqual(added, a.compound_interest()) self.assertEqual(new_balance, a.get_balance())
def create_account(self, account_type): """ method for creating bank account objects constructs instances of the Account subclasses with customer attributes: -customer name -time of method call -a random 7-digit integer -type of account; a method argument, determines which subclass of Account is created returns the account number and prints a message containing the account number """ rand_num = random.randint(1000000, 10000000) if account_type.lower() == "checking": #new_account = CheckingAccount (self._name, str(datetime.datetime.now()), random.randint(1000000,10000000), account_type, balance=0.0) self._customer_account_list[rand_num] = CheckingAccount( self._name, str(datetime.datetime.now()), rand_num, account_type, balance=0.0) if account_type.lower() == "savings": #new_account = SavingsAccount (self._name, str(datetime.datetime.now()),random.randint(1000000,10000000), account_type, balance=0.0) self._customer_account_list[rand_num] = SavingsAccount( self._name, str(datetime.datetime.now()), rand_num, account_type, balance=0.0) print("account # is {}".format(rand_num)) print("account number is {}".format(rand_num)) return rand_num
def test_create_account(self): name = 'Jaime' number = 6732 balance = 10000 interest = 0.01 a = SavingsAccount(name, number, balance, interest) self.assertIsInstance(a, SavingsAccount) self.assertIsInstance(a, Account)
def main(): savings_account_01 = SavingsAccount(100) print("Saving account balance: $", savings_account_01.get_balance(), sep="") checking_account_01 = CheckingAccount(500) print("Checking account balance: $", checking_account_01.get_balance(), sep="") print("") print("Making deposit into checking account for 75$...") checking_account_01.deposit_funds(75) print("New checking account balance: $", checking_account_01.get_balance(), sep="") print("") print("Making deposit into savings account for 300$...") savings_account_01.deposit_funds(300) print("New savings account balance: $", savings_account_01.get_balance(), sep="") print("") transfer_funds(checking_account_01, savings_account_01, 300) print("New checking account balance: $", checking_account_01.get_balance(), sep="") print("New savings account balance: $", savings_account_01.get_balance(), sep="") print("")
def create_account_for_customer(self, c, account_type): """creates a new account for customer""" account_num = randint(1, 100000000) if account_type == "Savings": new_account = SavingsAccount(c.get_name(),datetime.date.today().ctime(),\ account_num, account_type) elif account_type == "Checking": new_account = CheckingAccount(c.get_name(),datetime.date.today().ctime(),\ account_num, account_type) c.create_account(account_type)
except InsufficientFunds as my_error: print(str(my_error)) print(michelle.get_balance()) try: michelle.make_withdrawal(5) except MaxNumberOfWithdrawals as max_error: print(str(max_error)) except InsufficientFunds as my_error: print(str(my_error)) print(michelle.get_balance()) print("Your account balance is: £" + str(michelle.get_balance())) print("-" * 30) # Savings account account3 = SavingsAccount("Sally", 500000, 2.50, 3.25, 5) print(account3) print("-" * 30) account4 = SavingsAccount("Jonny Cash", 50, 0.5, 5, 4) print(account4) try: account4.make_withdrawal(15) except MaxNumberOfWithdrawals as max_error: print(str(max_error)) except InsufficientFunds as my_error: print(str(my_error)) print(account4.get_balance()) try: account4.make_withdrawal(60)
# print(jessie.check_balance()) # # print(jessie.no_of_friends) # print(jessie.recommend_a_friend()) # print(jessie.no_of_friends) # print(jessie.check_balance()) # print(jessie.recommend_a_friend()) # print(jessie.recommend_a_friend()) # print(jessie.recommend_a_friend()) # print(jessie.recommend_a_friend()) # print(jessie.recommend_a_friend()) # print(jessie.check_balance()) # # jessie.withdraw(100) # # print(jessie.check_balance()) # # vicky = CurrentAccount("vicky", "QA", "1980-05-10", 1000, 10) # # print(vicky.check_balance()) # print(vicky.withdraw(20)) # print(vicky.withdraw(-300)) # print(vicky.withdraw(991)) from savings_account import SavingsAccount michelle = SavingsAccount("michelle", "obama", "1995-05-10", 2.5, 200) print(michelle.check_balance()) print(michelle.get_savings_goal(5000, "2025-02-31"))
def savings_A(): check = 1 print("Great! I need some information to start:") acc_name = input("What is the name of the account holder? ") acc_num = input("What is the account number? ") start_b = input("What is the starting balance? $") ir = input("What is the interest rate? " + "%") user = SavingsAccount(acc_name, float(acc_num), float(start_b), float(ir)) while check == 1: savings_Option_menu = input("""What would you like to do? [d] Deposit [w] Withdraw [a] Add monthly interest [q] Quit Enter an option:""") if savings_Option_menu == "d": value = input("How much would you like to deposit? $") user.deposit_Money(float(value)) print("Your account balanace is now $" + str(round(user.getBal(), 2)) + ".") if savings_Option_menu == "w": value = input("How much do you want to withdraw? $") user.withdrawl_Money(float(value)) print("Your account balanace is now $" + str(round(user.getBal(), 2)) + ".") if savings_Option_menu == "a": user.monthlyIR() print("Your account balanace is now $" + str(round(user.getBal(), 2)) + ".") if savings_Option_menu == "q": print("Your final account balance is $" + str(round(user.getBal(), 2)) + ",have a great day!") check = 0 break option = ""
from savings_account import SavingsAccount from checking_account import CheckingAccount savings_account = SavingsAccount(1111, 2222, 0) savings_account.deposit(100) savings_account.deposit(150) savings_account.deposit(280) savings_account.withdraw(10) savings_account.withdraw(15) savings_account.withdraw(1000) checking_account = CheckingAccount(agency=1111, account_number=3333, balance=0, limit=500) checking_account.deposit(100) checking_account.withdraw(250) checking_account.withdraw(260) checking_account.withdraw(500)
from random import randint from bank import Bank from checking_account import CheckingAccount from savings_account import SavingsAccount from customer import Customer bank = Bank() luiz = Customer('Luiz', 25) maria = Customer('Maria', 52) savings_account = SavingsAccount(1111, 32460, 0) checking_account = CheckingAccount(2222, 32461, 0) luiz.insert_account_number(savings_account) maria.insert_account_number(checking_account) bank.insert_account(savings_account) bank.insert_customer(luiz) bank.insert_account(checking_account) bank.insert_customer(maria) for customer in [luiz, maria]: if bank.authenticate(customer): customer.account.deposit(randint(500, 1000)) customer.account.withdraw(randint(50, 100)) else: print('Unauthenticated customer')