-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathaccounts.py
91 lines (67 loc) · 2.4 KB
/
accounts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# The SavingsAccount class represents a
# savings account.
import datetime
ERRORCODE_BASE=-20000
class SavingsAccount:
# The __init__ method accepts arguments for the
# account number, interest rate, and balance.
def __init__(self):
self.__account_num = "1234"
self.__interest_rate = 0.0
self.__balance = 0.0
# The following methods are mutators for the
# data attributes.
def set_account_num(self, account_num):
self.__account_num = account_num
def set_interest_rate(self, int_rate):
self.__interest_rate = int_rate
def set_balance(self, bal):
self.__balance = bal
# The following methods are accessors for the
# data attributes.
def get_account_num(self):
return self.__account_num
def get_interest_rate(self):
return self.__interest_rate
def get_balance(self):
return self.__balance
def withdraw_funds(self, amount):
if(self.__balance)>=amount:
x = self.__balance - amount
return x
else:
return ERRORCODE_BASE-1
def deposit_funds(self, amount):
self.__balance += amount
# The CD account represents a certificate of
# deposit (CD) account. It is a subclass of
# the SavingsAccount class.
class CD(SavingsAccount):
# The init method accepts arguments for the
# account number, interest rate, balance, and
# maturity date.
def __init__(self):
# Call the superclass __init__ method.
SavingsAccount.__init__(self)
# Initialize the __maturity_date attribute.
self.__maturity_date = ""
# The set_maturity_date is a mutator for the
# __maturity_date attribute.
def set_maturity_date(self, mat_date):
self.__maturity_date = mat_date
# The get_maturity_date method is an accessor
# for the __maturity_date attribute.
def get_maturity_date(self):
return self.__maturity_date
def renew_automatic(self, new_duration):
self.__maturity_date=self.__maturity_date+new_duration
def withdraw_funds(self, amount):
todays_date = datetime.date.today()
if todays_date >= self.__maturity_date:
if(self.__balance)>=amount:
x = self.__balance - amount
return x
else:
return ERRORCODE_BASE -1
else:
return ERRORCODE_BASE -2