Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Car
- attr_accessor :title, :mileage
- def initialize(title, price)
- @title = title
- @price = price
- end
- def get_price
- return @price
- end
- end
- class UsedCar < Car
- def initialize(title, price, mileage)
- @title = title
- @mileage = mileage
- @price = price
- end
- def get_price
- if @mileage > 50000
- price_used_car = (1 - 50000 / 100000) * @price
- else
- price_used_car = (1 - @mileage / 100000) * @price
- end
- end
- end
- class CarPriceCalculator
- def initialize(cars)
- @cars = cars
- end
- def check(title, price)
- audi.title is costs audi.get_price
- # "#{bmw.title} is costs #{bmw.get_price}"
- # "#{honda.title} is costs #{honda.get_price}, because its mileage is #{honda.mileage}"
- end
- end
- @cars = []
- audi = Car.new("Audi", 6000)
- # # puts "#{audi.title} is costs #{audi.get_price}"
- bmw = Car.new("BMW", 5000)
- # # puts "#{bmw.title} is costs #{bmw.get_price}, because its mileage is #{bmw.mileage}"
- honda = UsedCar.new("Honda", 4200, 10000)
- @cars << audi
- @cars << bmw
- @cars << honda
- check(title, price)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement