Guest User

Untitled

a guest
Jan 21st, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. class Tea
  2.  
  3. def initialize(name, price, shipping, weight)
  4. @name = name
  5. @price = price
  6. @shipping = shipping
  7. @weight = weight
  8. get_tea_details
  9. @total_price = total_price
  10. end
  11.  
  12. def get_tea_details
  13. puts "Enter name: "
  14. @name = gets.chomp
  15. puts "Enter price: "
  16. @price = gets.chomp.to_f
  17. puts "Enter shipping cost: "
  18. @shipping = gets.chomp.to_f
  19. puts "Enter weight: "
  20. @weight = gets.chomp.to_i
  21. end
  22.  
  23. def total_price
  24. @total_price = @price + @shipping
  25. end
  26.  
  27. def price_difference
  28. price_difference = t1.total_price - t2.total_price
  29. print "#{price_difference}"
  30. end
  31.  
  32. end
  33.  
  34. puts "Do you want to compare teas?: "
  35. answer = gets.chomp
  36. if answer == "yes"
  37. t1 = Tea.new(@name, @price, @shipping, @weight)
  38. t1 = Tea.new(@name, @price, @shipping, @weight)
  39. end
  40.  
  41. price_difference
  42.  
  43. class Tea
  44. attr_accessor :name, :price
  45.  
  46. def price_difference(other)
  47. print (@price - other.price).abs
  48. end
  49.  
  50. def compare(other)
  51. same = true
  52.  
  53. if(@name != other.name)
  54. puts "They have different names."
  55. same = false
  56. end
  57.  
  58. if(@price != other.price)
  59. puts "They have different prices."
  60. same = false
  61. end
  62.  
  63. if same
  64. puts "They are exactly the same!"
  65. end
  66. end
  67. end
  68.  
  69. t1 = Tea.new
  70. t2 = Tea.new
  71.  
  72. t1.compare t2
  73. "They are exactly the same!"
Add Comment
Please, Sign In to add comment