diff --git a/README.md b/README.md index c4832e941..20ddd1938 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ When our test failures leave us confused and stuck, let's use the detailed proje The first two tests in wave 1 imply: -- There is a module (file) named `vendor.py` inside of the `swap_meet` package (folder) +- There is a module (file) named `vendor.py` inside of the `swap_meet` package (folder) --> - Inside this module, there is a class named `Vendor` - Each `Vendor` will have an attribute named `inventory`, which is an empty list by default - When we create initialize an instance of `Vendor`, we can optionally pass in a list with the keyword argument `inventory` @@ -192,10 +192,10 @@ The first tests in wave 2 imply: - Inside this module, there is a class named `Item` - Each `Item` will have an attribute named `category`, which is an empty string by default -- When we initialize an instance of `Item`, we can optionally pass in a string with the keyword argument `category` +- When we initialize an instance of `Item`, we can optionally pass in a string with the keyword argument `category` --> - Instances of `Vendor` have an instance method named `get_by_category` - It takes one argument: a string, representing a category - - This method returns a list of `Item`s in the inventory with that category + - This method returns a list of `Item`s in the inventory with that category --> ### Wave 3 @@ -233,7 +233,7 @@ The tests in wave 4 imply: The tests in Wave 5 imply there are three additional modules with three additional classes: - `Clothing` - - Has an attribute `category` that is `"Clothing"` + - Has an attribute `category` that is `"Clothing"` --> - Its stringify method returns `"The finest clothing you could wear."` - `Decor` - Has an attribute `category` that is `"Decor"` diff --git a/swap_meet/clothing.py b/swap_meet/clothing.py index 3b77c3367..520364005 100644 --- a/swap_meet/clothing.py +++ b/swap_meet/clothing.py @@ -1,2 +1,10 @@ -class Clothing: - pass +from swap_meet.item import Item + +class Clothing(Item): + def __init__(self, condition = 0): + # super().__init__(category = "Clothing") + ## super().__init__(condition) + self.category = "Clothing" + self.condition = condition + def __str__(self): + return "The finest clothing you could wear." \ No newline at end of file diff --git a/swap_meet/decor.py b/swap_meet/decor.py index c8b45bb28..384f1f2a3 100644 --- a/swap_meet/decor.py +++ b/swap_meet/decor.py @@ -1,2 +1,10 @@ -class Decor: - pass +from swap_meet.item import Item + +class Decor(Item): + + def __init__(self, condition = 0): + self.category = "Decor" + self.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 index 2f9dff68a..3f2a04a10 100644 --- a/swap_meet/electronics.py +++ b/swap_meet/electronics.py @@ -1,2 +1,10 @@ -class Electronics: - pass +from swap_meet.item import Item + +class Electronics(Item): + def __init__(self, condition = 0): + self.category = "Electronics" + self.condition = condition + + def __str__(self): + return "A gadget full of buttons and secrets." + diff --git a/swap_meet/item.py b/swap_meet/item.py index ba0d9777b..8966a76a5 100644 --- a/swap_meet/item.py +++ b/swap_meet/item.py @@ -1,2 +1,18 @@ class Item: - pass + def __init__(self, category = ""): + self.category = category + def __str__(self): + return "Hello World!" + def condition_description(self): + if self.condition < 1: + return "poor" + elif self.condition < 2: + return "bad" + elif self.condition < 3: + return "okay" + elif self.condition < 4: + return "decent" + elif self.condition < 5: + return "nearly new" + else: + return "this is so bad it does not have a condition description" diff --git a/swap_meet/vendor.py b/swap_meet/vendor.py index dd3c4caab..23220a101 100644 --- a/swap_meet/vendor.py +++ b/swap_meet/vendor.py @@ -1,2 +1,57 @@ +from swap_meet.item import Item + class Vendor: - pass + def __init__(self, inventory = []): + self.inventory = inventory + + def add(self, item): + self.inventory.append(item) + return item + + def remove(self, item): + if item in self.inventory: + self.inventory.remove(item) + return item + else: + return False + + def get_by_category(self, category): + inventory_list = [] + for item in self.inventory: + if item.category == category: + inventory_list.append(item) + return inventory_list + + def swap_items(self, friend, my_item, their_item): + if their_item in friend.inventory and my_item in self.inventory: + self.add(their_item) + friend.add(my_item) + self.remove(my_item) + friend.remove(their_item) + return True + else: + return False + + def swap_first_item(self, friend): + if self.inventory and friend.inventory: + self.swap_items(friend, self.inventory[0], friend.inventory[0]) + return True + return False + + def get_best_by_category(self, category): + items = self.get_by_category(category) + if not items: + return None + best = items[0] + for item in items: + if item.condition > best.condition: + best = item + return best + + + def swap_best_by_category(self, other, my_priority, their_priority): + my_best = self.get_best_by_category(their_priority) + their_best = other.get_best_by_category(my_priority) + if not my_best and their_best: + return False + return self.swap_items(other,my_best, their_best) \ No newline at end of file