From 7037722ae73d2b963c573d24d44798a5b875168d Mon Sep 17 00:00:00 2001 From: Maria Magana Date: Sun, 4 Apr 2021 18:00:50 -0700 Subject: [PATCH 1/4] added wave 1 and wave 2 reqs --- swap_meet/item.py | 4 ++++ swap_meet/vendor.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 swap_meet/item.py create mode 100644 swap_meet/vendor.py diff --git a/swap_meet/item.py b/swap_meet/item.py new file mode 100644 index 000000000..93fddc55f --- /dev/null +++ b/swap_meet/item.py @@ -0,0 +1,4 @@ + +class Item: + def __init__(self, category = ""): + self.category = category diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py new file mode 100644 index 000000000..289a35333 --- /dev/null +++ b/swap_meet/vendor.py @@ -0,0 +1,26 @@ +from swap_meet.item import Item + +class Vendor: + def __init__(self, inventory = None): + if inventory is None: + self.inventory = [] + else: + self.inventory = inventory + + def add(self, new_item): + self.inventory.append(new_item) + return new_item + + def remove(self, remove_item): + if remove_item not in self.inventory: + return False + else: + self.inventory.remove(remove_item) + return remove_item + + def get_by_category(self, category): + category_list = [] + for item in self.inventory: + if item.category == category: + category_list.append(item) + return category_list \ No newline at end of file From 0622b870468b2687a3d237aa6d627f352d0b9c93 Mon Sep 17 00:00:00 2001 From: Maria Magana Date: Mon, 5 Apr 2021 22:03:17 -0700 Subject: [PATCH 2/4] updated wave 3 and wave 4 --- swap_meet/item.py | 3 +++ swap_meet/vendor.py | 29 ++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index 93fddc55f..30e7abcc5 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -2,3 +2,6 @@ class Item: def __init__(self, category = ""): self.category = category + + def __str__(self): + return "Hello World!" diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 289a35333..17363dcce 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,5 +1,4 @@ -from swap_meet.item import Item - +#wave 1 class Vendor: def __init__(self, inventory = None): if inventory is None: @@ -23,4 +22,28 @@ def get_by_category(self, category): for item in self.inventory: if item.category == category: category_list.append(item) - return category_list \ No newline at end of file + return category_list + +#Wave 3 + def swap_items(self, friend, my_item, their_item): + if my_item not in self.inventory or \ + their_item not in friend.inventory: + return False + + self.remove(my_item) + friend.add(my_item) + friend.remove(their_item) + self.add(their_item) + + return True + +#Wave 4 + def swap_first_item(self, friend): + if len(self.inventory) < 1 or \ + len(friend.inventory) < 1: + return False + my_first_item = self.inventory[0] + their_first_item = friend.inventory[0] + self.swap_items(friend, my_first_item, their_first_item) + return True + \ No newline at end of file From 72cea363f403bf1f01e07c0af38ad5211b13577f Mon Sep 17 00:00:00 2001 From: Maria Magana Date: Tue, 6 Apr 2021 20:08:50 -0700 Subject: [PATCH 3/4] updated waves 5 and 6 --- swap_meet/clothing.py | 11 +++++++++++ swap_meet/decor.py | 12 ++++++++++++ swap_meet/electronics.py | 11 +++++++++++ swap_meet/item.py | 19 +++++++++++++++++-- swap_meet/vendor.py | 36 ++++++++++++++++++++++++++++++++---- 5 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 swap_meet/clothing.py create mode 100644 swap_meet/decor.py create mode 100644 swap_meet/electronics.py diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py new file mode 100644 index 000000000..bf809c303 --- /dev/null +++ b/swap_meet/clothing.py @@ -0,0 +1,11 @@ +#Wave 5 + +from swap_meet.item import Item + +class Clothing(Item): + + def __init__(self, condition=0): + Item.__init__(self, "Clothing", condition=condition) + + def __str__(self): + return "The finest clothing you could wear." diff --git a/swap_meet/decor.py b/swap_meet/decor.py new file mode 100644 index 000000000..9fa107a07 --- /dev/null +++ b/swap_meet/decor.py @@ -0,0 +1,12 @@ +#Wave 5 + +from swap_meet.item import Item + +class Decor(Item): + + def __init__(self, condition=0): + Item.__init__(self, "Decor", condition=condition) + + def __str__(self): + return "Something to decorate your space." + \ No newline at end of file diff --git a/swap_meet/electronics.py b/swap_meet/electronics.py new file mode 100644 index 000000000..21c6df170 --- /dev/null +++ b/swap_meet/electronics.py @@ -0,0 +1,11 @@ +#Wave 5 + +from swap_meet.item import Item + +class Electronics(Item): + + def __init__(self, condition=0): + Item.__init__(self, "Electronics", condition=condition) + + def __str__(self): + return "A gadget full of buttons and secrets." \ No newline at end of file diff --git a/swap_meet/item.py b/swap_meet/item.py index 30e7abcc5..f700c06da 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,7 +1,22 @@ - +#Wave 2 class Item: - def __init__(self, category = ""): + def __init__(self, category = "", condition=0,): self.category = category + self.condition = condition def __str__(self): return "Hello World!" + +#Wave 5 + def condition_description(self): + condition = self.condition + if condition >= 4.0: + return (f"The condition rating of this item is a {condition}, it's almost new") + elif condition >= 3.0: + return (f"The condition rating of this item is a {condition}, it's in good condition and gently used.") + elif condition >= 2.0: + return (f"The condition rating of this item is a {condition}, it's in fair condition and has cosmetic flaws and signs of use.") + elif condition >= 0.0: + return (f"The condition rating of this item is a {condition}, it's in poor condition and has some major cosmetic flaws.") + + diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index 17363dcce..c03f6e80e 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,4 +1,9 @@ -#wave 1 +from swap_meet.item import Item +from swap_meet.clothing import Clothing +from swap_meet.decor import Decor +from swap_meet.electronics import Electronics + +#Wave 1 class Vendor: def __init__(self, inventory = None): if inventory is None: @@ -16,7 +21,8 @@ def remove(self, remove_item): else: self.inventory.remove(remove_item) return remove_item - + +#Wave2 def get_by_category(self, category): category_list = [] for item in self.inventory: @@ -34,7 +40,6 @@ def swap_items(self, friend, my_item, their_item): friend.add(my_item) friend.remove(their_item) self.add(their_item) - return True #Wave 4 @@ -42,8 +47,31 @@ def swap_first_item(self, friend): if len(self.inventory) < 1 or \ len(friend.inventory) < 1: return False + my_first_item = self.inventory[0] their_first_item = friend.inventory[0] + self.swap_items(friend, my_first_item, their_first_item) return True - \ No newline at end of file + + +#Wave 6 + def get_best_by_category(self, category): + best_item = None + best_item_condition = -1 + for item in self.inventory: + if item.category == category: + if item.condition > best_item_condition: + best_item = item + best_item_condition = item.condition + return best_item + + def swap_best_by_category(self, other, my_priority, their_priority): + my_best_item = self.get_best_by_category(their_priority) + if my_best_item == None: + return False + their_best_item = other.get_best_by_category(my_priority) + if their_best_item == None: + return False + + return self.swap_items(other, my_best_item, their_best_item) \ No newline at end of file From b018bfbf0e26e908e253ae9398a6b9741fc864bd Mon Sep 17 00:00:00 2001 From: Maria Magana Date: Tue, 6 Apr 2021 20:13:02 -0700 Subject: [PATCH 4/4] updated some typos --- swap_meet/item.py | 2 +- swap_meet/vendor.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/swap_meet/item.py b/swap_meet/item.py index f700c06da..425a4bece 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -16,7 +16,7 @@ def condition_description(self): return (f"The condition rating of this item is a {condition}, it's in good condition and gently used.") elif condition >= 2.0: return (f"The condition rating of this item is a {condition}, it's in fair condition and has cosmetic flaws and signs of use.") - elif condition >= 0.0: + else: return (f"The condition rating of this item is a {condition}, it's in poor condition and has some major cosmetic flaws.") diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index c03f6e80e..40df4b265 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -22,7 +22,7 @@ def remove(self, remove_item): self.inventory.remove(remove_item) return remove_item -#Wave2 +#Wave 2 def get_by_category(self, category): category_list = [] for item in self.inventory: @@ -67,9 +67,11 @@ def get_best_by_category(self, category): return best_item def swap_best_by_category(self, other, my_priority, their_priority): + my_best_item = self.get_best_by_category(their_priority) if my_best_item == None: return False + their_best_item = other.get_best_by_category(my_priority) if their_best_item == None: return False