forked from xyluz/pythonclass
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBudget.py
More file actions
105 lines (85 loc) · 3.46 KB
/
Copy pathBudget.py
File metadata and controls
105 lines (85 loc) · 3.46 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
class Budget:
class Food:
def __init__(self, balance):
self.bal = balance
def getBalance(self):
return self.bal
def setBalance(self, value):
self.bal = value
class Clothing:
def __init__(self, balance):
self.bal = balance
def getBalance(self):
return self.bal
def setBalance(self, value):
self.bal = value
class Entertainment:
def __init__(self, balance):
self.bal = balance
def getBalance(self):
return self.bal
def setBalance(self, value):
self.bal = value
class Budget:
def __init__(self):
"""Instantiate the food, clothing ang entertainment class and initialize them with a balance of zero"""
self.food = Food(0)
self.clothing = Clothing(0)
self.entertainment = Entertainment(0)
self.pairs = {"food": self.food,
"clothing": self.clothing,
"entertainment": self.entertainment
}
def categoryIsValid(self, category):
"""Verifies if the category is valid"""
if category in self.pairs:
return True
return False
def deposit(self, amount, categ):
"""Deposit into the specified category"""
if self.categoryIsValid(categ) == True:
category = self.pairs[categ]
curBal = category.getBalance()
balAfterDeposit = amount + curBal
category.setBalance(balAfterDeposit)
print("Deposit successful.")
else:
print("Invalid category.")
def withdrawal(self, amount, categ):
"""Withdraws from the specified category"""
if self.categoryIsValid(categ) == True:
category = self.pairs[categ]
curBal = category.getBalance()
if curBal < amount:
print("Error. Insufficient funds.")
else:
balAfterWithdrawal = curBal - amount
category.setBalance(balAfterWithdrawal)
print("Take your cash...#{amount}")
else:
print("Invalid category.")
def showCategoryBalances(self):
"""Displays balance for all categories"""
foodBalance = self.food.getBalance()
clothingBalance = self.clothing.getBalance()
entertainmentBalance = self.entertainment.getBalance()
print("The balance for the food category is: {foodBalance}")
print("The balance for the clothing category is: {clothingBalance}")
print("The balance for the entertainment category is: {entertainmentBalance}")
def transfer(self, amount, srcCateg, destCateg):
"""Tranfers from the source category to another category"""
if (self.categoryIsValid(srcCateg) and self.categoryIsVald(destCateg)) == True:
src, dest = self.pairs[srcCateg], self.pairs[destCateg]
srcBalance = src.getBalance()
if srcBalance >= amount:
srcRemBalance = srcBalance - amount
src.setBalance(srcRemBalance)
destCurBalance = dest.getBalance()
destFinBalance = destCurBalance + amount
dest.setBalance(destFinBalance)
print("Transfer Succesful.")
else:
print("Error. Insufficient funds.")
else:
print("Invalid category.")
#Instantiate the Budget Class