Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. class Box
  2. attr_accessor :length, :width, :height, :volume
  3.  
  4. def initialize length, width, height
  5. fail "Please give positive, non-zero numbers for all 3 values" unless
  6. length.class == Integer &&
  7. length > 0 &&
  8. width.class == Integer &&
  9. width > 0 &&
  10. height.class == Integer &&
  11. height > 0
  12.  
  13. @length = length
  14. @width = width
  15. @height = height
  16. end
  17.  
  18. def dimensions
  19. puts "Dimensions:\n - Length: #{@length} ft.\n - Width: #{@width} ft.\n - Height: #{@height} ft."
  20. end
  21.  
  22. def volume
  23. vol = @length * @width * @height
  24. puts "Volume: #{vol} cu. ft."
  25. end
  26. end
  27.  
  28.  
  29. # EXECUTE >>>>>>>>>>>>>>>>>>>>>>>>>>>>
  30.  
  31. puts "Let's make a box!"
  32. puts "Please enter an integer for the length of the box:"
  33. length = gets.chomp.to_i
  34. puts "Please enter an integer for the width of the box:"
  35. width = gets.chomp.to_i
  36. puts "Please enter an integer for the height of the box:"
  37. height = gets.chomp.to_i
  38.  
  39. box = Box.new(length, width, height)
  40. puts "\n*********\nHere's the box you made:\n"
  41. box.dimensions
  42. puts ""
  43. box.volume
  44. puts "*********"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement