#################################################################### #Institute : Mahindra Ecole Centrale # #Subject : CS101-Introduction to computer programming, Lab-14 # #Author : Vipin.K # #Description : A simple banking software demo to introduce OOP # #################################################################### """ A simple banking software demo to introduce OOP ----------------------------------------------- """ import bank #Import the bank module print __doc__ customers = {} #Dictionary to store all customers accnt_number = 1 #Variable to generate account number. After each new account creation, incremented by 1 while 1: #Infinite loop so that program never terminates print 'Enter the option\n' #Menu for the operator print '1.Add a new customer\t\t2.Remove a customer\n3.Add an account\t\t', print '4.Remove an account\n5.Deposite\t\t\t6.Withdraw\n', print '7.Pay interest\t\t\t8.Change interest rate' response = input() #Catch the operator input if response == 1: print '\nAdd a New Customer' print '______________\n' name = raw_input('Name:') #Get the new customer details dob = raw_input('DoB (DD/MM/YYYY):') address = raw_input('Address:') customers[name] = bank.customer(name,dob,address) #Create a new customer object and store in the dictionary. customer name #used as the key. In future for uniqueness can replace with internally generated customer id. #(Followed by banks such as HDFC for internet banking) print 'Customer successfully added\n' print 'Total number of customers',len(customers) #Just to see how many customers bank presently have elif response == 2: print '\nRemove a Customer' print '__________________\n' name = raw_input('\nEnter the customer name:') #To remove a customer, get the customer name if name in customers: #Check whether the entered customer exists customers.pop(name) #If yes, delete print 'Customer successfully deleted\n' print 'Total number of customers',len(customers) else: print 'Customer not found!!\n' #If not found, give a warning elif response == 3: print '\nAdd new account' print '__________________\n' name = raw_input('\nEnter the customer name:') #Get the customer name to link the account if name in customers: #Check if the customer exists init_deposit = input('\nInitial deposit:') #Get the initial deposit also customers[name].add_account(accnt_number,init_deposit) #Call the method with account number and #initial deposit to create a new account print 'Account',accnt_number,'successfully added to customer',name accnt_number += 1 #Automatically increment the account number else: #If customer name is not found, give a warning print 'Customer not found, please check the name' elif response == 4: print 'Remove an account' print '__________________\n' name = raw_input('\nEnter the customer name:') #Again get the customer whose account to be removed if name in customers: print 'Accounts linked to this customer' #List all account numbers linked to this customer i=1 print 'No\tAccount No.' for account in customers[name].accounts: print i,'\t',account i+=1 accnt_num = input('Enter account to remove:') #Get the account number to be removed if accnt_num in customers[name].accounts.keys(): #Check if that account number really exists customers[name].remove_account(accnt_num) #If yes, call the method to remove the account print 'Account',accnt_num,'successfully removed from customer',name else: print 'Account number not found, please check again\n' #If account number not found, give a warning else: print 'Customer not found, please check the name' #If customer name is not found, give a warning elif response == 5: print 'Deposit' print '_______\n' name = raw_input('\nEnter the customer name:') if name in customers: print 'Accounts linked to this customer' i=1 print 'No\tAccount No.' for account in customers[name].accounts: print i,'\t',account i+=1 accnt_num = input('Enter account for deposit:') if accnt_num in customers[name].accounts.keys(): amount = input('Amount to be deposited:') balance = customers[name].accounts[accnt_num].deposit(amount) #Call the method to deposit print 'Successfully deposited Rs.',amount,'to',customers[name].accounts[accnt_num] print 'Present Balance:',balance #Just display the present balance else: print 'Account number not found, please check again\n' else: print 'Customer not found, please check again\n' elif response == 6: print 'Withdraw' print '_______\n' name = raw_input('\nEnter the customer name:') if name in customers: print 'Accounts linked to this customer' i=1 print 'No\tAccount No.' for account in customers[name].accounts: print i,'\t',account i+=1 accnt_num = input('Enter account for withdrawal:') if accnt_num in customers[name].accounts.keys(): amount = input('Amount to be withdrawn:') balance = customers[name].accounts[accnt_num].withdraw(amount) print 'Successfully withdrew Rs.',amount,'from',customers[name].accounts[accnt_num] print 'Present Balance:',balance else: print 'Account number not found, please check again\n' else: print 'Customer not found, please check again\n' elif response == 7: print '\nPay Interest' print '__________________\n' print 'Customer\tAccount No\t\tInterest\tBalance' #Pay interest to every account of each customer print '______________________________________________________________' for customer in customers: for account in customers[customer].accounts: (interest,balance) = customers[customer].accounts[account].calc_interest() print customer,'\t\t',account,'\t\t\t',interest,'\t\t',balance #Just print how much interest each account got elif response == 8: print '\nChange Interest Rate' print '__________________\n' new_int_rate = input('New Rate:') bank.account.int_rate = new_int_rate #Please note we are chaing the class attribute, not the object print 'Successfully changed interest rate to',bank.account.int_rate else: #If the operator gives a wrong choice, warn. print '\nWrong choice!!' print '______________\n'