-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rock-lin #58
base: master
Are you sure you want to change the base?
Rock-lin #58
Changes from all commits
469d8c3
1ed23c7
d89649c
b3e2d04
a45093e
a1219ee
7dbd53e
caa0e98
4be82c8
ad4ce08
38706c3
47585a1
853ade5
e08085e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from swap_meet.item import Item | ||
|
||
|
||
class Clothing(Item): | ||
def __init__(self, category="Clothing", condition=0): | ||
super().__init__(category, condition) | ||
|
||
def __str__(self): | ||
return "The finest clothing you could wear." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from swap_meet.item import Item | ||
|
||
|
||
class Decor(Item): | ||
def __init__(self, category="Decor", condition=0): | ||
super().__init__(category, condition) | ||
Comment on lines
+4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment from Clothing can be applied here |
||
|
||
def __str__(self): | ||
return "Something to decorate your space." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from swap_meet.item import Item | ||
|
||
|
||
class Electronics(Item): | ||
def __init__(self, category="Electronics", condition=0): | ||
super().__init__(category, condition) | ||
Comment on lines
+4
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment from Clothing can be applied here |
||
|
||
def __str__(self): | ||
return "A gadget full of buttons and secrets." |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# from swap_meet.vendor import Vendor | ||
|
||
# ***WAVE 1/5*** | ||
class Item: | ||
def __init__(self, category=None, condition=0): | ||
self.category = category | ||
self.condition = condition | ||
if category == None: | ||
self.category = "" | ||
else: | ||
self.category = category | ||
|
||
# ***WAVE 3*** | ||
def __str__(self): | ||
return "Hello World!" | ||
|
||
# ***WAVE 5*** | ||
def condition_description(self): | ||
if self.condition == 0: | ||
return "This is our lowest rating. This trash won't your treasure, trust us" | ||
elif self.condition == 1: | ||
return "Poor" | ||
elif self.condition == 2: | ||
return "Fair" | ||
elif self.condition == 3: | ||
return "Good" | ||
elif self.condition == 4: | ||
return "Like New" | ||
elif self.condition == 5: | ||
return "This is our highest rating, brand spankin' NEW" | ||
Comment on lines
+18
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like your condition description 😆 Another thing to add to this class is checking if the condition being passed is an integer. Another thing to think about is how would this conditional change if you were using float values instead? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
class Vendor: | ||
def __init__(self, inventory=None): | ||
self.inventory = inventory | ||
if inventory == None: | ||
self.inventory = [] | ||
else: | ||
self.inventory = inventory | ||
|
||
def add(self, item): | ||
self.item = item | ||
self.inventory.append(item) | ||
return item | ||
|
||
def remove(self, item): | ||
self.item = item | ||
if item in self.inventory: | ||
self.inventory.remove(item) | ||
return item | ||
return False | ||
|
||
def get_by_category(self, category): | ||
items_matching_category = [] | ||
for item in self.inventory: | ||
if category == item.category: | ||
items_matching_category.append(item) | ||
return items_matching_category | ||
|
||
def swap_items(self, Vendor, my_item, their_item): | ||
if (my_item in self.inventory) and (their_item in Vendor.inventory): | ||
self.remove(my_item) | ||
self.add(their_item) | ||
Vendor.add(my_item) | ||
Vendor.remove(their_item) | ||
return True | ||
return False | ||
|
||
def swap_first_item(self, Vendor): | ||
if (self.inventory and Vendor.inventory): | ||
return self.swap_items(Vendor, self.inventory[0], Vendor.inventory[0]) | ||
return False | ||
Comment on lines
+28
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm... this passed the test however I'd heavily caution in using a Class to add and remove items from. "self" refers to an instance of the Vendor class so when you're adding and removing items from a data structure in the Class itself, you're also affecting the instances. |
||
|
||
def get_best_by_category(self, category): | ||
list = [] | ||
for item in self.get_by_category(category): | ||
list.append(item.condition) | ||
for item in self.get_by_category(category): | ||
if item.condition == max(list): | ||
return item | ||
Comment on lines
+43
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because |
||
|
||
def swap_best_by_category(self, other, my_priority, their_priority): | ||
return self.swap_items(other, self.get_best_by_category( | ||
their_priority), other.get_best_by_category(my_priority)) | ||
Comment on lines
+50
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great reuse of methods here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great use of the super constructor!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, it's still possible to accidentally override
category
in the instance constructor. You are right in using a default argument assign "Clothing" to category, however, we can move that code over to the super constructor instead.