/tutorial/parking/car.e

http://github.com/tybor/Liberty · Specman e · 37 lines · 28 code · 6 blank · 3 comment · 0 complexity · c0c648fec76182855d8f3e110e7e6ebc MD5 · raw file

  1. class CAR
  2. creation {PARKING}
  3. make
  4. feature {ANY}
  5. number: INTEGER
  6. -- The number of the CAR.
  7. arrival_time: DATE
  8. -- Of this CAR in the parking.
  9. price (departure_time: DATE; hour_price: REAL): REAL is
  10. -- Compute the price to pay according to `departure_time' and `hour_price'.
  11. require
  12. departure_time >= arrival_time
  13. local
  14. nb_min: TUPLE[INTEGER, INTEGER]
  15. do
  16. nb_min := arrival_time.day_night_to(departure_time)
  17. Result := (hour_price / 4 * nb_min.second + hour_price * nb_min.first) / 60
  18. end
  19. feature {}
  20. make (n: like number; at: like arrival_time) is
  21. require
  22. n > 0
  23. at /= Void
  24. do
  25. number := n
  26. arrival_time := at
  27. ensure
  28. number = n
  29. arrival_time = at
  30. end
  31. end -- class CAR