Skip to content
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

Complete Code #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ A `LeaseContract` is created by passing the following attributes:

The `total_value()` of a `LeaseContract` will be computed in this way: `vehicle.sale_price() + (lease_multiplier) - (discount if employee) * `. In this case `lease_multiplier` depends on the vehicle and is computed in the following way:

* `Car`: `sale_price() + (sale_price() * 1.2 / length_in_months)`.
* `Motorcycle`: `sale_price() + (sale_price() * 1 / length_in_months)`
* `Truck`: `sale_price() + (sale_price() * 1.7 / length_in_months)`
* `Car`: `sale_price() * 1.2 / length_in_months`.
* `Motorcycle`: `sale_price() * 1 / length_in_months`
* `Truck`: `sale_price() * 1.7 / length_in_months`

The `monthly_value` of the contract will be just the total value divided by the amount of months: `total_value() / length_in_months`.

Expand Down Expand Up @@ -104,4 +104,4 @@ Given a Car with `sale_price()` $15,000, a regular customer (not employee) and 1
Given a Truck with `sale_price()` $35,000, a regular customer (not employee) and 36 `length_in_months`:

* `total_value()`: `sale_price() + (sale_price() * 1.7 / length_in_months)` = `$35,000 + (35,000 * 1.7 / 36)` = `$36,652.77`
* `monthly_value()`: `total_value() / monthly_payments` = `$36,652.78 / 36` = `$1,018.13`
* `monthly_value()`: `total_value() / monthly_payments` = `$36,652.78 / 36` = `$1,018.13`
36 changes: 31 additions & 5 deletions dealership/contracts.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
class Contract(object):
pass
from dealership.customers import Customer, Employee
from dealership.vehicles import Car, Motorcycle, Truck

class Contract(object):
def __init__(self , vehicle, customer):
self.vehicle = vehicle
self.customer = customer

class BuyContract(Contract):
def __init__(self, vehicle, customer, monthly_payments):
pass

super(BuyContract, self).__init__(vehicle, customer)
self.monthly_payments = monthly_payments

def total_value(self):
discount = 0
if(self.customer.is_employee()):
discount = self.customer.DISCOUNT
total = self.vehicle.sale_price() + (self.vehicle.INTREST_RATE * self.monthly_payments * self.vehicle.sale_price()/100)
return total - (total * discount)

def monthly_value(self):
return self.total_value() / self.monthly_payments

class LeaseContract(Contract):
def __init__(self, vehicle, customer, length_in_months):
pass
super(LeaseContract, self).__init__(vehicle, customer)
self.length_in_months = length_in_months

def total_value(self):
discount = 0
if(self.customer.is_employee()):
discount = self.customer.DISCOUNT
total = self.vehicle.sale_price() + (self.vehicle.sale_price() * self.vehicle.LEASE_MUTIPLIER / self.length_in_months)

return total - ( total * discount)

def monthly_value(self):
return self.total_value() / self.length_in_months
17 changes: 12 additions & 5 deletions dealership/customers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
class Person(object):
def __init__(self, first_name, last_name, email):
pass

def __init__(self, first_name, last_name, email):
self.first_name = first_name
self.last_name = last_name
self.email = email


class Customer(Person):
pass

def is_employee(self):
return False


class Employee(Person):
pass
DISCOUNT = 0.10

def is_employee(self):
return True
34 changes: 26 additions & 8 deletions dealership/vehicles.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
class Vehicle(object):
def __init__(self, maker, model, year, base_price, miles):
pass


self.maker = maker
self.model = model
self.year = year
self.base_price = base_price
self.miles = miles

def sale_price(self):
return (self.base_price * self.SALE_PRICE_MULTIPLIER)

def purchase_price(self):
return (self.sale_price() - (self.PURCHASE_PRICE_MULTIPLIER * self.miles))

class Car(Vehicle):
pass

SALE_PRICE_MULTIPLIER = 1.2
PURCHASE_PRICE_MULTIPLIER = 0.004
INTREST_RATE = 1.07
LEASE_MUTIPLIER = 1.2

class Motorcycle(Vehicle):
pass

SALE_PRICE_MULTIPLIER = 1.1
PURCHASE_PRICE_MULTIPLIER = 0.009
INTREST_RATE = 1.03
LEASE_MUTIPLIER = 1

class Truck(Vehicle):
pass
SALE_PRICE_MULTIPLIER = 1.6
PURCHASE_PRICE_MULTIPLIER = 0.02
INTREST_RATE = 1.11
LEASE_MUTIPLIER = 1.7