home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / SmallEiffel.lha / SmallEiffel / lib_show / parking / level.e < prev    next >
Text File  |  1999-06-05  |  3KB  |  119 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class LEVEL
  17.  
  18. creation {ANY}
  19.    make
  20.  
  21. feature {ANY}
  22.  
  23.    count: INTEGER;
  24.          -- Total count of occupied places.
  25.  
  26.    free_count: INTEGER is
  27.       do
  28.          Result := park.count - count;
  29.       end;
  30.  
  31.    capacity : INTEGER is
  32.       do
  33.          Result := count + free_count;
  34.       end;
  35.  
  36.    full: BOOLEAN is
  37.       do
  38.          Result := count = capacity;
  39.       end;
  40.  
  41. feature {ANY} -- Modifications :
  42.  
  43.    make(max_cars: INTEGER) is
  44.       require
  45.          max_cars > 0;
  46.       do
  47.          !!park.make(1,max_cars);
  48.          !!tickets.make(park.lower,park.upper);
  49.          count := 0;
  50.       ensure
  51.          count = 0;
  52.       end;
  53.  
  54.    arrival(car: INTEGER; arrival_time: DATE) is
  55.       require
  56.          not full;
  57.          car > 0;
  58.       local
  59.          i: INTEGER;
  60.          stop: BOOLEAN;
  61.          ticket: TICKET;
  62.       do
  63.          from
  64.             i := park.lower;
  65.             stop := false;
  66.          until
  67.             stop
  68.          loop
  69.             if park @ i <= 0 then
  70.                stop := true;
  71.                park.put(car,i);
  72.                !!ticket.make(arrival_time);
  73.                tickets.put(ticket,i);
  74.                count := count + 1;
  75.             end;
  76.             i := i + 1;
  77.          end;
  78.       ensure
  79.          count >= old count + 1;
  80.       end;
  81.  
  82.    departure(car: INTEGER; departure_time: DATE; hour_price: REAL): REAL is
  83.          -- Gives price to pay or -1 when car is not at this level.
  84.       require
  85.          car > 0;
  86.       local
  87.          i: INTEGER;
  88.       do
  89.          i := park.index_of(car);
  90.          if (i > park.upper) then
  91.             Result := -1;
  92.          else
  93.             Result := (tickets @ i).price(departure_time,hour_price);
  94.             tickets.put(Void,i);
  95.             park.put(0,i);
  96.             count := count - 1;
  97.          end;
  98.       end;
  99.  
  100. feature {NONE}
  101.  
  102.    park: ARRAY[INTEGER];
  103.  
  104.    tickets: ARRAY[TICKET];
  105.  
  106. invariant
  107.  
  108.    count >= 0;
  109.  
  110.    free_count >= 0;
  111.  
  112.    capacity = count + free_count;
  113.  
  114.    capacity >= 1;
  115.  
  116.    tickets.count = park.count;
  117.  
  118. end -- LEVEL
  119.