TheBlackPopeSJ

Final Project code

May 3rd, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 14.62 KB | None | 0 0
  1.  
  2. # ===============================================================================
  3. # CLASS DEFINITIONS
  4. # ===============================================================================
  5.  
  6.  
  7.  
  8. # --------------------------------------------
  9. # Customer Class
  10. # Abstract: Contains methods and properties for working with objCustomer
  11. # --------------------------------------------
  12. class clsCustomer:
  13.  
  14.     # create list of accounts for customer
  15.     lstAccounts = []
  16.  
  17.  
  18.     # class constructor, creates instance of customer object
  19.     def __init__(self, strFirstName, strLastName, strSSN):
  20.         self.strFirstName = strFirstName
  21.         self.strLastName = strLastName
  22.         self.strSSN = strSSN
  23.  
  24.  
  25.     # method to display combined balance of a given customer's accounts
  26.     def displayTotalBalance(self):
  27.         dblTotalBalance = sum(objAccount.dblBalance for objAccount in lstAccounts)
  28.  
  29.  
  30.  
  31. # --------------------------------------------
  32. # Account Class
  33. # Abstract: Contains methods and properties for working with generic Account object
  34. # --------------------------------------------
  35. class clsAccount:
  36.  
  37.  
  38.     # class constructor, initializes generic account object
  39.     def __init__(self, strOwnerSSN, dblBalance, strAccountType, strAccountName, objCustomer):
  40.         self.strOwnerSSN = strOwnerSSN
  41.         self.dblBalance = dblBalance
  42.         self.strAccountType = strAccountType
  43.         self.strAccountName = strAccountName
  44.  
  45.         # add account to list of customer's accounts
  46.         objCustomer.lstAccounts.append(self)
  47.  
  48.  
  49.     # method to validate that input is numeric
  50.     def isNumeric(self, strInput):
  51.         try:
  52.             float(strInput)
  53.             return True
  54.         except ValueError:
  55.             print("ERROR: INPUT MUST BE NUMBERS ONLY.")
  56.             pass
  57.  
  58.  
  59.     # method to display balance of given account
  60.     def displayBalance(self, strCustomerSSN, strAccountName):
  61.         return self.dblBalance
  62.  
  63.  
  64.     # method to validate deposits are numeric, positive, not zero
  65.     def validateDeposit(self, dblAmount):
  66.         if clsAccount.isNumeric(self, dblAmount) == True:
  67.             if dblAmount == 0:
  68.                 print("ERROR: DEPOSIT AMOUNT CANNOT BE ZERO.")
  69.                 return False
  70.             elif dblAmount < 0:
  71.                 print("ERROR: DEPOSIT AMOUNT CANNOT BE LESS THAN ZERO.")
  72.                 return False
  73.             else:
  74.                 return True
  75.  
  76.  
  77.     # method to deposit funds in checking or savings account
  78.     def Deposit(self, dblAmount, strAccountName):
  79.         if clsAccount.isNumeric(self, dblAmount) == True:
  80.             if clsAccount.validateDeposit(self, dblAmount) == True:
  81.                 self.dblBalance += dblAmount
  82.  
  83.  
  84.     # method to validate withdrawal amount is numeric, positive, not zero
  85.     def validateWithdraw(self, dblAmount):
  86.         if clsAccount.isNumeric(self, dblAmount) == True:
  87.             if dblAmount == 0:
  88.                 print("ERROR: WITHDRAWAL AMOUNT CANNOT BE ZERO.")
  89.                 return False
  90.             elif dblAmount < 0:
  91.                 print("ERROR: WITHDRAWAL AMOUNT CANNOT BE LESS THAN ZERO.")
  92.                 return False
  93.             else:
  94.                 return True
  95.  
  96.  
  97.     # method to withdraw funds from checking or savings account
  98.     def Withdraw(self, dblAmount, objFromAccount):
  99.         if clsAccount.isNumeric(self, dblAmount) == True:
  100.             if clsAccount.validateWithdraw(self, dblAmount) == True:
  101.                 if objFromAccount.strAccountType == "savings" and objFromAccount.dblBalance - dblAmount < 500:
  102.                     print("ERROR: SAVINGS ACCOUNT BALANCE CANNOT BE LESS THAN $500.00")
  103.                 elif objFromAccount.strAccountType == "checking" and objFromAccount.dblBalance - dblAmount < 0:
  104.                     objFromAccount.dblBalance -= dblAmount
  105.                     clsCheckingAccount.applyOverdraftFee(self, 20, objFromAccount)
  106.                 else:
  107.                     objFromAccount.dblBalance -= dblAmount
  108.  
  109.  
  110.     # method to validate transfer amount is positive, not zero
  111.     def validateTransfer(self, dblAmount, strAccountName):
  112.         if clsAccount.isNumeric(self, dblAmount) == True:
  113.             if dblAmount == 0:
  114.                 print("ERROR: TRANSFER AMOUNT CANNOT BE ZERO.")
  115.                 return False
  116.             elif dblAmount < 0:
  117.                 print("ERROR: TRANSFER AMOUNT CANNOT BE LESS THAN ZERO.")
  118.                 return False
  119.             else:
  120.                 return True
  121.  
  122.  
  123.     # method to transfer funds from one account to another
  124.     # can transfer funds among one customer's account or between one
  125.     #     customer's account and another customer's account
  126.     def transferFunds(self, dblAmount, objFromAccount, objToAccount, strCustomerSSN):
  127.         if clsAccount.isNumeric(self, dblAmount) == True:
  128.             if clsAccount.validateTransfer(dblAmount) == True:
  129.                 if objFromAccount.strAccountType == "savings" and objFromAccount.dblBalance - dblAmount < 500:
  130.                     print("ERROR: SAVINGS ACCOUNT BALANCE CANNOT BE LESS THAN $500.00")
  131.                 elif objFromAccount.strAccountType == "checking" and objFromAccount.dblBalance - dblAmount < 0:
  132.                     objToAccount.dblBalance += dblAmount
  133.                     objFromAccount -= dblAmount
  134.                     applyOverdraftFee(objFromAccount)
  135.                 else:
  136.                     objToAccount.dblBalance += dblAmount
  137.                     objFromAccount -= dblAmount
  138.  
  139.  
  140.  
  141. # --------------------------------------------
  142. # Checking Account Subclass
  143. # Abstract: Contains methods and properties for working with Checking Account objects,
  144. #           inherits clsAccount
  145. # --------------------------------------------
  146. class clsCheckingAccount(clsAccount):
  147.  
  148.  
  149.     # class constructor, initializes Checking Account object
  150.     # overrides parent class constructor
  151.     def __init__(self, strOwnerSSN, dblBalance, strAccountType, strAccountName, objCustomer):
  152.         clsAccount.__init__(self, strOwnerSSN, dblBalance, strAccountType, strAccountName, objCustomer)
  153.         self.strOwnerSSN = strOwnerSSN
  154.         self.dblBalance = dblBalance
  155.         self.strAccountType = strAccountType
  156.         self.strAccountName = strAccountName
  157.  
  158.  
  159.     # method to apply overdraft fee to accounts meeting criteria
  160.     def applyOverdraftFee(self, dblAmount, objAccount):
  161.  
  162.         # set value for overdraft fee
  163.         dblOverdraftFee = float(20)
  164.  
  165.         # apply overdraft fee
  166.         objAccount.dblBalance -= dblOverdraftFee
  167.  
  168.  
  169.  
  170. # --------------------------------------------
  171. # Savings Account Subclass
  172. # Abstract: Contains methods and properties for working with Savings Account objects,
  173. #           inherits clsAccount
  174. # --------------------------------------------
  175. class clsSavingsAccount(clsAccount):
  176.  
  177.  
  178.     # class constructor, initializes Savings Account object
  179.     # overrides parent constructor
  180.     def __init__(self, strOwnerSSN, dblBalance, strAccountType, strAccountName, objCustomer):
  181.  
  182.         # validate that opening balance is >= required amount before initializing object
  183.         if clsSavingsAccount.validateOpeningBalance(self, dblBalance) == True:
  184.             clsAccount.__init__(self, strOwnerSSN, dblBalance, strAccountType, strAccountName, objCustomer)
  185.             self.strOwnerSSN = strOwnerSSN
  186.             self.dblBalance = dblBalance
  187.             self.strAccountType = strAccountType
  188.             self.strAccountName = strAccountName
  189.  
  190.  
  191.     # method to validate deposit, transfer, and withdrawal amounts
  192.     def validateOpeningBalance(self, dblAmount):
  193.         if clsAccount.isNumeric(self, dblAmount) == True:
  194.             if dblAmount == 0:
  195.                 print("ERROR: OPENING BALANCE CANNOT BE ZERO.")
  196.                 return False
  197.             elif dblAmount < 0:
  198.                 print("ERROR: OPENING BALANCE CANNOT BE LESS THAN ZERO.")
  199.                 return False
  200.             elif dblAmount < 500:
  201.                 print("ERROR: OPENING BALANCE MUST BE AT LEAST $500.00")
  202.                 return False
  203.             else:
  204.                 return True
  205.        
  206.  
  207.  
  208. # ===============================================================================
  209. # MAIN MODULE
  210. # ===============================================================================
  211.  
  212. # use pretty print for test results
  213. import pprint
  214.  
  215.  
  216. # --------------------------------------------
  217. # Test 1:
  218. # Abstract: Show successful customer creation
  219. # --------------------------------------------
  220. print("==========================================================================")
  221. print("Test 1")
  222. Bob = clsCustomer("Bob", "Jones", "123456789")
  223. pprint.pprint(Bob.__dict__)
  224. print("==========================================================================")
  225.  
  226.  
  227.  
  228. # --------------------------------------------
  229. # Test 2:
  230. # Abstract: Show successful customer creation + opening checking account
  231. # --------------------------------------------
  232. print("Test 2")
  233. Samantha = clsCustomer("Samantha", "Park", "987654321")
  234. SamanthaCheckingAccount = clsCheckingAccount("987654321", 300.00, "checking", "SamanthaCheckingAcct", Samantha)
  235. pprint.pprint(Samantha.__dict__)
  236. pprint.pprint(SamanthaCheckingAccount.__dict__)
  237. print("==========================================================================")
  238.  
  239.  
  240.  
  241. # --------------------------------------------
  242. # Test 3:
  243. # Abstract: Show successful deposit to checking
  244. # --------------------------------------------
  245. print("Test 3")
  246. print("Samantha checking balance is", SamanthaCheckingAccount.dblBalance)
  247. SamanthaCheckingAccount.dblBalance += 500.00
  248. print("Samantha deposited $500.00. Balance is now", SamanthaCheckingAccount.dblBalance)
  249. print("==========================================================================")
  250.  
  251.  
  252.  
  253. # --------------------------------------------
  254. # Test 4:
  255. # Abstract: Show failed attempt to create customer + open savings account,
  256. #           due to insufficient funds
  257. # --------------------------------------------
  258. print("Test 4")
  259. Jess = clsCustomer("Jess", "Jones", "456789123")
  260. JessSavingsAccount = clsSavingsAccount("456789123", 200.00, "savings", "JessSavingsAccount", Jess)
  261. print("==========================================================================")
  262.  
  263.  
  264.  
  265. # --------------------------------------------
  266. # Test 5:
  267. # Abstract: Show successful customer creation + opening savings account
  268. # --------------------------------------------
  269. print("Test 5")
  270. Dave = clsCustomer("Dave", "Malloy", "111223333")
  271. DaveSavingsAccount = clsSavingsAccount("111223333", 600.00, "savings", "DaveSavingsAccount", Dave)
  272. pprint.pprint(DaveSavingsAccount.__dict__)
  273. print("==========================================================================")
  274.  
  275.  
  276.  
  277. # --------------------------------------------
  278. # Test 6:
  279. # Abstract: Show successful deposit into savings account
  280. # --------------------------------------------
  281. print("Test 6")
  282. print("The current balance of DaveSavingsAccount is", DaveSavingsAccount.dblBalance)
  283. DaveSavingsAccount.Deposit(300, DaveSavingsAccount)
  284. print("Dave deposited $300. DaveSavingsAccount balance is now", DaveSavingsAccount.dblBalance)
  285. print("==========================================================================")
  286.  
  287.  
  288.  
  289. # --------------------------------------------
  290. # Test 7:
  291. # Abstract: Show failed withdrawal from savings due to dropping below $500 minimum
  292. # --------------------------------------------
  293. print("Test 7")
  294. intWithdrawalAmount = DaveSavingsAccount.dblBalance - 100
  295. print("The current balance of DaveSavingsAccount is", DaveSavingsAccount.dblBalance)
  296. print("Dave will attempt to withdraw", intWithdrawalAmount)
  297. DaveSavingsAccount.Withdraw(intWithdrawalAmount, DaveSavingsAccount)
  298. print("==========================================================================")
  299.  
  300.  
  301.  
  302. # --------------------------------------------
  303. # Test 8:
  304. # Abstract: Show successful withdrawal from savings
  305. # --------------------------------------------
  306. print("Test 8")
  307. intWithdrawalAmount = 100
  308. print("The current balance of DaveSavingsAccount is", DaveSavingsAccount.dblBalance)
  309. print("Dave will attempt to withdraw", intWithdrawalAmount)
  310. DaveSavingsAccount.Withdraw(intWithdrawalAmount, DaveSavingsAccount)
  311. print("The balance of DaveSavingsAccount is now", DaveSavingsAccount.dblBalance)
  312. print("==========================================================================")
  313.  
  314.  
  315.  
  316. # --------------------------------------------
  317. # Test 9:
  318. # Abstract: Show successful withdrawal from checking,
  319. #           but overdraft fee applied due to balance going below zero
  320. # --------------------------------------------
  321. print("Test 9")
  322. Sarah = clsCustomer("Sarah", "Whitehall", "999887777")
  323. SarahCheckingAccount = clsAccount("999887777", 500, "checking", "SarahCheckingAccount", Sarah)
  324. print("Sarah has a checking account balance of $500. She will attempt to withdraw $600.")
  325. SarahCheckingAccount.Withdraw(600, SarahCheckingAccount)
  326. print("Sarah successfully withdrew the money. After the overdraft fee, her balance is now", SarahCheckingAccount.dblBalance)
  327. print("==========================================================================")
  328.  
  329.  
  330.  
  331. # --------------------------------------------
  332. # Test 10:
  333. # Abstract: Show successful withdrawal from checking
  334. # --------------------------------------------
  335. print("Test 10")
  336. SarahCheckingAccount2 = clsAccount("999887777", 500, "checking", "SarahCheckingAccount2", Sarah)
  337. print("Sarah has a second checking account balance of $500. She will attempt to withdraw $400.")
  338. SarahCheckingAccount2.Withdraw(400, SarahCheckingAccount2)
  339. print("Sarah successfully withdrew the money. After the withdrawal, her balance is now", SarahCheckingAccount2.dblBalance)
  340.  
  341.  
  342. print("==========================================================================")
  343.  
  344.  
  345.  
  346. # --------------------------------------------
  347. # Test 11:
  348. # Abstract: Show successful transfer, but overdraft fee applied
  349. #           to checking FromAccount due to balance going below zero
  350. # --------------------------------------------
  351. print("Test 11")
  352. print("Sarah has two checking accounts. She will transfer $200 from the second account to the first.")
  353. print("The current balance of the first checking account is", SarahCheckingAccount.dblBalance)
  354. print("The current balance of the second checking account is", SarahCheckingAccount2.dblBalance)
  355. clsAccount.transferFunds(200, SarahCheckingAccount2, SarahCheckingAccount, "999887777")
  356. print("The current balance of the first checking account is now", SarahCheckingAccount.dblBalance)
  357. print("The current balance of the second checking account is now", SarahCheckingAccount2.dblBalance)
  358.  
  359. print("==========================================================================")
  360.  
  361.  
  362.  
  363. # --------------------------------------------
  364. # Test 12:
  365. # Abstract: Show failed transfer due to savings FromAccount going below $500 limit
  366. # --------------------------------------------
  367. print("Test 12")
  368.  
  369.  
  370.  
  371. print("==========================================================================")
  372.  
  373.  
  374.  
  375. # --------------------------------------------
  376. # Test 13:
  377. # Abstract: Show successful transfer
  378. # --------------------------------------------
  379. print("Test 13")
  380.  
  381.  
  382.  
  383. print("==========================================================================")
  384.  
  385.  
  386.  
  387. # --------------------------------------------
  388. # Test 14:
  389. # Abstract: Show successful customer creation
  390. # --------------------------------------------
  391. print("Test 14")
  392.  
  393.  
  394.  
  395. print("==========================================================================")
  396.  
  397.  
  398.  
  399. # --------------------------------------------
  400. # Test 15:
  401. # Abstract: Show successful customer creation
  402. # --------------------------------------------
  403. print("Test 15")
  404.  
  405.  
  406.  
  407.  
  408. print("==========================================================================")
Add Comment
Please, Sign In to add comment