fork download
  1. class Order
  2. def initialize
  3. @positions = []
  4. end
  5.  
  6. def add(title, price, count)
  7. @positions << [title, price, count]
  8. end
  9.  
  10. def print
  11. printf("% 20s % 15s % 15s % 15s\n", 'Наименование', 'Количество', 'Цена', 'Итого')
  12. @positions.each do |position|
  13. printf("% 20s % 15d % 15.2f % 15.2f\n", position[0], position[2], position[1], position[1]*position[2])
  14. end
  15. printf("% 68.2f\n", total)
  16. end
  17.  
  18. def total
  19. subtotal = @positions.reduce(0.0) do |result, position|
  20. result += position[1]*position[2]
  21. end
  22. if subtotal >= 200
  23. subtotal * 0.8
  24. elsif subtotal >= 100
  25. subtotal * 0.9
  26. else
  27. subtotal
  28. end
  29. end
  30. end
Success #stdin #stdout 0s 6500KB
stdin
Standard input is empty
stdout
Standard output is empty