Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. """
  2. File: savingsaccount.py
  3. This module defines the SavingsAccount class.
  4. """
  5. class SavingsAccount:
  6. """This class represents a savings account
  7. with the owner's name, PIN, and balance."""
  8. RATE = 0.02 # Single rate for all accounts
  9. def __init__(self, name, pin, balance = 0.0):
  10. self.name = name
  11. self.pin = pin
  12. self.balance = balance
  13. def __str__(self):
  14. """Returns the string rep."""
  15. result = 'NAME: ' + self.name + '\n'
  16. result += 'PIN: ' + self.pin + '\n'
  17. result += 'Balance: ' + str(self.balance)
  18. return result
  19. def getBalance(self):
  20. """Returns the current balance."""
  21. return self.balance
  22. def getName(self):
  23. """Returns the current name."""
  24. return self.name
  25. def getPin(self):
  26. """Returns the current pin."""
  27. return self.pin
  28. def deposit(self, amount):
  29. """If the amount is valid, adds it
  30. to the balance and returns None;
  31. otherwise, returns an error message."""
  32. self.balance += amount
  33. return None
  34. def withdraw(self, amount):
  35. """If the amount is valid, sunstract it
  36. from the balance and returns None;
  37. otherwise, returns an error message."""
  38. if amount < 0:
  39. return "Amount must be >= 0"
  40. elif self.balance < amount:
  41. return "Insufficient funds"
  42. else:
  43. self.balance -= amount
  44. return None
  45. def computeInterest(self):
  46. """Computes, deposits, and returns the interest."""
  47. interest = self.balance * SavingsAccount.RATE
  48. self.deposit(interest)
  49. return interest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement