Skip to main content
Code Review

Return to Question

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I tried to help someone in Stackoverflow help someone in Stackoverflow with a refactoring exercise. Did many changes to his original code and made a somewhat decent solution (at least in my eyes). Was thinking, whether someone can critique on my implementation.

class Theatre
 COST = { running: 3, fixed: 180 }
 attr_accessor :number_of_audience, :ticket_price
 def revenue
 @number_of_audience * @ticket_price
 end
 def total_cost
 COST[:fixed] + (@number_of_audience * COST[:running])
 end
 def net
 revenue - total_cost
 end
 def profit?
 net > 0
 end
end
class TheatreCLI
 def initialize
 @theatre = Theatre.new
 end
 def seek_number_of_attendes
 print 'Number of audience: '
 @theatre.number_of_audience = gets.chomp.to_i
 end
 def seek_ticket_price
 print 'Ticket price: '
 @theatre.ticket_price = gets.chomp.to_i
 end
 def print_revenue
 puts "Revenue for the theatre is RM #{@theatre.revenue}."
 end
 def print_profit
 message_prefix = @theatre.profit? ? 'Profit made' : 'Loss incurred'
 puts "#{message_prefix} #{@theatre.net.abs}."
 end
 def self.run
 TheatreCLI.new.instance_eval do
 seek_ticket_price
 seek_number_of_attendes
 print_revenue
 print_profit
 end
 end
end
TheatreCLI.run

I tried to help someone in Stackoverflow with a refactoring exercise. Did many changes to his original code and made a somewhat decent solution (at least in my eyes). Was thinking, whether someone can critique on my implementation.

class Theatre
 COST = { running: 3, fixed: 180 }
 attr_accessor :number_of_audience, :ticket_price
 def revenue
 @number_of_audience * @ticket_price
 end
 def total_cost
 COST[:fixed] + (@number_of_audience * COST[:running])
 end
 def net
 revenue - total_cost
 end
 def profit?
 net > 0
 end
end
class TheatreCLI
 def initialize
 @theatre = Theatre.new
 end
 def seek_number_of_attendes
 print 'Number of audience: '
 @theatre.number_of_audience = gets.chomp.to_i
 end
 def seek_ticket_price
 print 'Ticket price: '
 @theatre.ticket_price = gets.chomp.to_i
 end
 def print_revenue
 puts "Revenue for the theatre is RM #{@theatre.revenue}."
 end
 def print_profit
 message_prefix = @theatre.profit? ? 'Profit made' : 'Loss incurred'
 puts "#{message_prefix} #{@theatre.net.abs}."
 end
 def self.run
 TheatreCLI.new.instance_eval do
 seek_ticket_price
 seek_number_of_attendes
 print_revenue
 print_profit
 end
 end
end
TheatreCLI.run

I tried to help someone in Stackoverflow with a refactoring exercise. Did many changes to his original code and made a somewhat decent solution (at least in my eyes). Was thinking, whether someone can critique on my implementation.

class Theatre
 COST = { running: 3, fixed: 180 }
 attr_accessor :number_of_audience, :ticket_price
 def revenue
 @number_of_audience * @ticket_price
 end
 def total_cost
 COST[:fixed] + (@number_of_audience * COST[:running])
 end
 def net
 revenue - total_cost
 end
 def profit?
 net > 0
 end
end
class TheatreCLI
 def initialize
 @theatre = Theatre.new
 end
 def seek_number_of_attendes
 print 'Number of audience: '
 @theatre.number_of_audience = gets.chomp.to_i
 end
 def seek_ticket_price
 print 'Ticket price: '
 @theatre.ticket_price = gets.chomp.to_i
 end
 def print_revenue
 puts "Revenue for the theatre is RM #{@theatre.revenue}."
 end
 def print_profit
 message_prefix = @theatre.profit? ? 'Profit made' : 'Loss incurred'
 puts "#{message_prefix} #{@theatre.net.abs}."
 end
 def self.run
 TheatreCLI.new.instance_eval do
 seek_ticket_price
 seek_number_of_attendes
 print_revenue
 print_profit
 end
 end
end
TheatreCLI.run
Post Reopened by Abbas, edmz, RubberDuck, Pimgd, Heslacher
Removed comment
Source Link
RubberDuck
  • 31.1k
  • 6
  • 73
  • 176

I tried to help someone in Stackoverflow with a refactoring exercise. Did many changes to his original code and made a somewhat decent solution (at least in my eyes). Was thinking, whether someone can critique on my implementation.

EDIT: Have added code to the post itself, hope it will now me removed from hold.

class Theatre
 COST = { running: 3, fixed: 180 }
 attr_accessor :number_of_audience, :ticket_price
 def revenue
 @number_of_audience * @ticket_price
 end
 def total_cost
 COST[:fixed] + (@number_of_audience * COST[:running])
 end
 def net
 revenue - total_cost
 end
 def profit?
 net > 0
 end
end
class TheatreCLI
 def initialize
 @theatre = Theatre.new
 end
 def seek_number_of_attendes
 print 'Number of audience: '
 @theatre.number_of_audience = gets.chomp.to_i
 end
 def seek_ticket_price
 print 'Ticket price: '
 @theatre.ticket_price = gets.chomp.to_i
 end
 def print_revenue
 puts "Revenue for the theatre is RM #{@theatre.revenue}."
 end
 def print_profit
 message_prefix = @theatre.profit? ? 'Profit made' : 'Loss incurred'
 puts "#{message_prefix} #{@theatre.net.abs}."
 end
 def self.run
 TheatreCLI.new.instance_eval do
 seek_ticket_price
 seek_number_of_attendes
 print_revenue
 print_profit
 end
 end
end
TheatreCLI.run

I tried to help someone in Stackoverflow with a refactoring exercise. Did many changes to his original code and made a somewhat decent solution (at least in my eyes). Was thinking, whether someone can critique on my implementation.

EDIT: Have added code to the post itself, hope it will now me removed from hold.

class Theatre
 COST = { running: 3, fixed: 180 }
 attr_accessor :number_of_audience, :ticket_price
 def revenue
 @number_of_audience * @ticket_price
 end
 def total_cost
 COST[:fixed] + (@number_of_audience * COST[:running])
 end
 def net
 revenue - total_cost
 end
 def profit?
 net > 0
 end
end
class TheatreCLI
 def initialize
 @theatre = Theatre.new
 end
 def seek_number_of_attendes
 print 'Number of audience: '
 @theatre.number_of_audience = gets.chomp.to_i
 end
 def seek_ticket_price
 print 'Ticket price: '
 @theatre.ticket_price = gets.chomp.to_i
 end
 def print_revenue
 puts "Revenue for the theatre is RM #{@theatre.revenue}."
 end
 def print_profit
 message_prefix = @theatre.profit? ? 'Profit made' : 'Loss incurred'
 puts "#{message_prefix} #{@theatre.net.abs}."
 end
 def self.run
 TheatreCLI.new.instance_eval do
 seek_ticket_price
 seek_number_of_attendes
 print_revenue
 print_profit
 end
 end
end
TheatreCLI.run

I tried to help someone in Stackoverflow with a refactoring exercise. Did many changes to his original code and made a somewhat decent solution (at least in my eyes). Was thinking, whether someone can critique on my implementation.

class Theatre
 COST = { running: 3, fixed: 180 }
 attr_accessor :number_of_audience, :ticket_price
 def revenue
 @number_of_audience * @ticket_price
 end
 def total_cost
 COST[:fixed] + (@number_of_audience * COST[:running])
 end
 def net
 revenue - total_cost
 end
 def profit?
 net > 0
 end
end
class TheatreCLI
 def initialize
 @theatre = Theatre.new
 end
 def seek_number_of_attendes
 print 'Number of audience: '
 @theatre.number_of_audience = gets.chomp.to_i
 end
 def seek_ticket_price
 print 'Ticket price: '
 @theatre.ticket_price = gets.chomp.to_i
 end
 def print_revenue
 puts "Revenue for the theatre is RM #{@theatre.revenue}."
 end
 def print_profit
 message_prefix = @theatre.profit? ? 'Profit made' : 'Loss incurred'
 puts "#{message_prefix} #{@theatre.net.abs}."
 end
 def self.run
 TheatreCLI.new.instance_eval do
 seek_ticket_price
 seek_number_of_attendes
 print_revenue
 print_profit
 end
 end
end
TheatreCLI.run
Add code to post
Source Link
Jikku Jose
  • 237
  • 1
  • 7

I tried to help someone in Stackoverflow with a refactoring exercise. Did many changes to his original code and made a somewhat decent solution (at least in my eyes). Was thinking, whether someone can critique on my implementation.

EDIT: Have added code to the post itself, hope it will now me removed from hold.

class Theatre
 COST = { running: 3, fixed: 180 }
 attr_accessor :number_of_audience, :ticket_price
 def revenue
 @number_of_audience * @ticket_price
 end
 def total_cost
 COST[:fixed] + (@number_of_audience * COST[:running])
 end
 def net
 revenue - total_cost
 end
 def profit?
 net > 0
 end
end
class TheatreCLI
 def initialize
 @theatre = Theatre.new
 end
 def seek_number_of_attendes
 print 'Number of audience: '
 @theatre.number_of_audience = gets.chomp.to_i
 end
 def seek_ticket_price
 print 'Ticket price: '
 @theatre.ticket_price = gets.chomp.to_i
 end
 def print_revenue
 puts "Revenue for the theatre is RM #{@theatre.revenue}."
 end
 def print_profit
 message_prefix = @theatre.profit? ? 'Profit made' : 'Loss incurred'
 puts "#{message_prefix} #{@theatre.net.abs}."
 end
 def self.run
 TheatreCLI.new.instance_eval do
 seek_ticket_price
 seek_number_of_attendes
 print_revenue
 print_profit
 end
 end
end
TheatreCLI.run

I tried to help someone in Stackoverflow with a refactoring exercise. Did many changes to his original code and made a somewhat decent solution (at least in my eyes). Was thinking, whether someone can critique on my implementation.

I tried to help someone in Stackoverflow with a refactoring exercise. Did many changes to his original code and made a somewhat decent solution (at least in my eyes). Was thinking, whether someone can critique on my implementation.

EDIT: Have added code to the post itself, hope it will now me removed from hold.

class Theatre
 COST = { running: 3, fixed: 180 }
 attr_accessor :number_of_audience, :ticket_price
 def revenue
 @number_of_audience * @ticket_price
 end
 def total_cost
 COST[:fixed] + (@number_of_audience * COST[:running])
 end
 def net
 revenue - total_cost
 end
 def profit?
 net > 0
 end
end
class TheatreCLI
 def initialize
 @theatre = Theatre.new
 end
 def seek_number_of_attendes
 print 'Number of audience: '
 @theatre.number_of_audience = gets.chomp.to_i
 end
 def seek_ticket_price
 print 'Ticket price: '
 @theatre.ticket_price = gets.chomp.to_i
 end
 def print_revenue
 puts "Revenue for the theatre is RM #{@theatre.revenue}."
 end
 def print_profit
 message_prefix = @theatre.profit? ? 'Profit made' : 'Loss incurred'
 puts "#{message_prefix} #{@theatre.net.abs}."
 end
 def self.run
 TheatreCLI.new.instance_eval do
 seek_ticket_price
 seek_number_of_attendes
 print_revenue
 print_profit
 end
 end
end
TheatreCLI.run
Post Closed as "Not suitable for this site" by Jamal
Source Link
Jikku Jose
  • 237
  • 1
  • 7
Loading
lang-rb

AltStyle によって変換されたページ (->オリジナル) /