-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserClass.py
179 lines (164 loc) · 5.42 KB
/
UserClass.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#general methods for password check
def hasNumbers(inputString):
return any(char.isdigit() for char in inputString)
def hasCapitals(inputString):
return any(char.isupper() for char in inputString)
class Password(object):
def __init__(self, passw= ""):
self.password = passw
def __repr__(self):
return self.password
def changePassword(self, p):
self.password = p
def checkPassword(self):
password = self.password
if hasCapitals(password) and hasNumbers(password) and len(password) >= 6:
return bool(True)
else:
return bool(False)
class User(object):
def __init__(self, firstName = "", lastName = "", age = 0, ID = [0,0,0,0], password = ""):
self.firstName, self.lastName, self.age, self.ID = firstName, lastName, age, ID
self.password = Password(password)
def check_name(self):
if self.firstName == "":
print("First name was not specified.")
if self.lastName == "":
print("Last name was not specified.")
if not self.lastName == "" and not self.firstName == "":
print("Names are specified.")
def __repr__(self):
return "Name:{first} {last} \n Age:{age} \n ID: {ID} \n Password: {passw}".format(first = self.firstName, last= self.lastName, age = self.age, ID = self.ID, passw = "*" * len(self.password.password))
def getName(self):
return self.firstName + ' ' + self.lastName
def setID(self, a, b, c, d):
self.ID[0] = a
self.ID[1] = b
self.ID[2] = c
self.ID[3] = d
def setName(self, a, b):
self.firstName = a
self.lastName = b
def setAge(self, a):
self.age = a
def getAge(self):
return self.age
def getID(self):
idd = ""
for i in self.ID:
idd += str(i)
return idd
def setPassword(self, a):
self.password.changePassword(a)
def checkPass(self):
self.password.checkPassword()
def getPassword(self):
return self.password.password
#test User
'''me = User("Ryan","Arndtsen", 19, [4,5,4,7], "Ryan999")
print(me)
print(me.getPassword())
print(me.checkPass())
me.setID(1,2,3,4)
me.setAge(10)
me.setName(me.firstName,"Swag")
print(me)
you = User("", "", 14, [3,2,2,2])
you.check_name
print('\n')'''
class Giver(User):
def __init__(self, firstName = "", lastName = "", age = 0, ID = [0,0,0,0], password = "", funds = 0, totalGiven = 0, rewards = []):
User.__init__(self, firstName, lastName, age, ID, password)
self.funds = funds
self.tG = totalGiven
self.rewards = rewards
def __repr__(self):
return User.__repr__(self) + "\n Funds: {f} \n Rewards = {r}".format(f = self.funds, r = self.rewards)
def addFunds(self, a):
self.funds += a
def getFunds(self):
return self.funds
def donate(self, a):
self.funds -= a
self.tG += a
def gettG(self):
return self.tG
def rewardStatus(self):
if self.tG < 100:
return "No reward"
elif self.tG >= 100 and self.tG < 200:
return "Medium reward"
else:
return "Big reward"
def claimReward(self):
if self.rewardStatus() == "No reward":
self.tG = 0
return "Yikes"
elif self.rewardStatus() == "Medium reward":
self.rewards.append("Med")
self.tG = 0
return "Medium reward claimed"
else:
self.rewards.append("Big")
self.tG = 0
return "Big reward claimed"
def checkRewards(self):
return self.rewards
#test Giver
"""hi = Giver("Frank","Ocean", 13, [1,1,1,1], "hellO666", 1500, 14, [])
hi.checkPass()
print(hi)
print(hi.addFunds(20))
print(hi.getFunds())
print(hi.donate(143))
print(hi.gettG())
print(hi.rewardStatus())
print(hi.claimReward())
print(hi.checkRewards())
print('\n')"""
class Hobo(User):
def __init__(self, firstName = "", lastName = "", age = 0, ID = [0,0,0,0], password = "", balance = 0, totalCashedIn = 0):
User.__init__(self, firstName, lastName, age, ID, password)
self.balance = balance
self.tCI = totalCashedIn
def __repr__(self):
return User.__repr__(self) + "\n Balance: {bal}".format(bal = self.balance)
def updateBalance(self, a):
self.balance += a
def getBalance(self):
return self.balance
def cashIn(self):
if self.balance <= 0:
return "No funds to cash in."
self.tCI += self.balance
self.balance = 0
def gettCI(self):
return self.tCI
#test Hobo
'''rob = Hobo("Ronald","Weasley", 42, [10,22,3,1], "exnto", 0, 10)
print(rob)
rob.updateBalance(5)
print(rob.getBalance())
print(rob.cashIn())
print(rob.gettCI())
rob.checkPass()
print("\n")'''
#additional methods
def donation(Giver, Hobo, amount):
if Giver.getFunds() < amount:
print("Insufficient funds")
else:
Giver.donate(amount)
Hobo.updateBalance(amount)
print("Thank you for your donation.")
def log_in(User): #might have to change when implementing database
x = input("Enter ID:")
y = input("Enter Password:")
if x == User.getID() and y == User.getPassword():
print("Welcome {n}".format(n = User.getName()))
else:
if x != User.getID():
print("Incorrect ID")
if y != User.getPassword():
print("Incorrect Password")
log_in(User)