Question: What code smells can you identify? Refactor the code to remove these smells. class Movie REGULAR = 0 NEW_RELEASE = 1 CHILDRENS = 2 attr_reader

What code smells can you identify?

Refactor the code to remove these smells.

class Movie REGULAR = 0 NEW_RELEASE = 1 CHILDRENS = 2 attr_reader :title attr_accessor :price_code def initialize(title, price_code) @title = title @price_code = price_code end end class Rental attr_reader :movie, :days_rented def initialize(movie, days_rented) @movie = movie @days_rented = days_rented end end class Customer attr_reader :name def initialize(name) @name = name @rentals = [] end def add_rental(arg) @rentals << arg end def statement total_amount = 0 frequent_renter_points = 0 result = "Rental Record for #{@name} " @rentals.each do |element| this_amount=0 case element.movie.price_code when Movie::REGULAR this_amount += 2 this_amount += (element.days_rented -2) * 1.5 if element.days_rented > 2 when Movie::NEW_RELEASE this_amount += element.days_rented * 3 when Movie::CHILDRENS this_amount += 1.5 this_amount += (element.days_rented -3) * 1.5 if element.days_rented > 3 end #add frequent_renter_points frequent_renter_points += 1 #add bonus for a two day new releaes rental if element.movie.price_code == Movie::NEW_RELEASE && element.days_rented > 1 frequent_renter_points += 1 end #show figures for this rental result += "\t" + element.movie.title + "\t" + this_amount.to_s + " " total_amount += this_amount end #add footer lines result += "Amount owed is #{total_amount} " result += "you earned #{frequent_renter_points} frequent renter points" result end end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!