Last active
April 3, 2017 15:41
-
-
Save Cr4ck3r/2dc66bca2e56fcf7293f811173786a85 to your computer and use it in GitHub Desktop.
Bicycle Industry Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Wheel: | |
| #Have a model name | |
| #Have a weight | |
| #Have a cost to produce | |
| #There should be a total of three different wheel types | |
| def __init__(self,name,weight,cost): | |
| self.name = name | |
| self.weight = weight | |
| self.cost = cost | |
| class Frame: | |
| #Can be made of aluminum, carbon, or steel | |
| #Have a weight | |
| #Have a cost to produce | |
| def __init__(self,material,weight,cost): | |
| self.material = material | |
| self.weight = weight | |
| self.cost = cost | |
| class Bicycle: | |
| #Have a model name | |
| #Have a weight | |
| #Have a cost to produce | |
| def __init__(self,name,wheel,frame, manufacturer): | |
| self.name = name | |
| self.wheel = wheel | |
| self.frame = frame | |
| self.retail_cost = 0 | |
| self.weight = 2 * wheel.weight + frame.weight | |
| self.prod_cost = 2 * wheel.cost + frame.cost | |
| self.manufacturer = manufacturer | |
| manufacturer.add_bike(self) | |
| def __repr__(self): | |
| return self.name | |
| class Shop: | |
| #Have a name | |
| #Have an inventory of different bicycles | |
| #Sell bicycles with a margin over their cost | |
| #Can see how much profit they have made from selling bikes | |
| def __init__(self,name,inventory,margin): | |
| self.name = name | |
| self.inventory = inventory | |
| self.margin = margin | |
| self.profit = 0 | |
| for bike in self.inventory.keys(): | |
| bike.retail_cost = int(self.margin * bike.prod_cost) | |
| class Customer: | |
| #Have a name | |
| #Have a fund of money to buy a bike | |
| #Can buy and own a new bicycle | |
| def __init__(self,name,funds): | |
| self.name = name | |
| self.funds = funds | |
| def purchase(self,bike,shop): | |
| if self.funds >= bike.retail_cost: | |
| self.funds -= bike.retail_cost | |
| shop.inventory[bike] -= 1 | |
| return True | |
| else: | |
| return False | |
| class BikeManufacturer: | |
| def __init__(self, name, percent): | |
| self.name = name | |
| self.bikes = [] | |
| self.percent = percent | |
| def add_bike(self, bike): | |
| self.bikes.append(bike) | |
| # Wheel Types: Name, weight(lbs includes rim), cost(dollars per wheel) | |
| wide_wh = Wheel("Wide", 7, 55) | |
| race_wh = Wheel("Racing", 4, 70) | |
| bmx_wh = Wheel("BMX", 7, 35) | |
| offr_wh = Wheel("Offroad", 10, 20) | |
| basi_wh = Wheel("Basic", 5, 10) | |
| # Frame Types: Name(should be matierial type), weight (lbs), Cost(dollars) | |
| steel_fr = Frame("Steel", 15, 110) | |
| titan_fr = Frame("Titanium", 9, 500) | |
| alumi_fr = Frame("Aluminum", 8, 250) | |
| carbo_fr = Frame ("Carbon Fibre", 5, 800) | |
| basic_fr = Frame("Basic", 20, 40) | |
| # Manufatureres: Name, margin | |
| seven = BikeManufacturer("Se7en", 1.1) | |
| five = BikeManufacturer("F1ve", 1.15) | |
| #Bikes: Name, wheel, frame, maker | |
| drift = Bicycle("Drift Bike", wide_wh, alumi_fr, seven) | |
| road = Bicycle("Road Bike", race_wh, carbo_fr, five) | |
| beach = Bicycle("Beach Bike", offr_wh, alumi_fr, seven) | |
| mountain = Bicycle("Mountain Bike", offr_wh, titan_fr, five) | |
| bmx = Bicycle("BMX Bike", bmx_wh, steel_fr, five) | |
| basic = Bicycle("Cheap Bike",basi_wh, basic_fr, seven) | |
| #SHOP: Name, Inventory, Margin(profit) | |
| red_cycle = Shop("Red Cycle",{ | |
| drift: 1, | |
| road: 12, | |
| beach: 2, | |
| mountain: 14, | |
| bmx: 2, | |
| basic: 0 | |
| }, 1.1) | |
| #CUSTOMER: Name, Funds | |
| c1 = Customer("Steve",200) | |
| c2 = Customer("Jim",500) | |
| c3 = Customer("Joe",1000) | |
| #process example, inventory before and after purchase | |
| print(c1.funds) | |
| print (red_cycle.inventory) | |
| if c1.purchase(basic, red_cycle): | |
| print ("Purchase success") | |
| else: | |
| print ("Purchase failed") | |
| print ("The Basic Bike costs: " + str(basic.retail_cost)) | |
| print (red_cycle.inventory) | |
| print (c1.funds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment