home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog4 / meals3.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  2.9 KB  |  118 lines

  1.                                     -- Chapter 26 - Program 3
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Meals3 is
  6.  
  7.    HOURS : constant := 1;
  8.    type PERSON is (BILL, JOHN);
  9.  
  10.    package Enum_IO is new Text_IO.Enumeration_IO(PERSON);
  11.    use Enum_IO;
  12.  
  13.    task Bills_Day;
  14.  
  15.    task Johns_Day;
  16.  
  17.    task Restaurant is
  18.       entry Eat_A_Meal(Customer : PERSON);
  19.    end Restaurant;
  20.  
  21.    task Burger_Boy is
  22.       entry Eat_A_Meal(Customer : PERSON);
  23.    end Burger_Boy;
  24.  
  25.    task body Bills_Day is
  26.       My_Name : PERSON := BILL;
  27.    begin
  28.       delay 1.0 * HOURS;
  29.       select
  30.          Restaurant.Eat_A_Meal(My_Name);
  31.       else
  32.          Burger_Boy.Eat_A_Meal(My_Name);
  33.       end select;
  34.       delay 1.0 * HOURS;
  35.       select
  36.          Restaurant.Eat_A_Meal(My_Name);
  37.       or
  38.          delay 0.1 * HOURS;
  39.          Burger_Boy.Eat_A_Meal(My_Name);
  40.       end select;
  41.       delay 1.0 * HOURS;
  42.       Restaurant.Eat_A_Meal(My_Name);
  43.    end Bills_Day;
  44.  
  45.    task body Johns_Day is
  46.       My_Name : PERSON := JOHN;
  47.    begin
  48.       delay 0.4 * HOURS;
  49.       Restaurant.Eat_A_Meal(My_Name);
  50.       delay 0.4 * HOURS;
  51.       Restaurant.Eat_A_Meal(My_Name);
  52.       delay 4.0 * HOURS;
  53.       Restaurant.Eat_A_Meal(My_Name);
  54.    end Johns_Day;
  55.  
  56.    task body Restaurant is
  57.    begin
  58.       loop
  59.          select
  60.             accept Eat_A_Meal(Customer : PERSON) do
  61.                Put(Customer);
  62.                Put_Line(" is ordering at the restaurant");
  63.                delay 0.5 * HOURS;
  64.                Put(Customer);
  65.                Put_Line(" is eating at the restaurant");
  66.                delay 0.5 * HOURS;
  67.             end Eat_A_Meal;
  68.          or
  69.             delay 1.5 * HOURS;
  70.             Put_Line("The restaurant is closed for the day");
  71.             exit;
  72.          end select;
  73.       end loop;
  74.    end Restaurant;
  75.  
  76.    task body Burger_Boy is
  77.    begin
  78.       loop
  79.          select
  80.             accept Eat_A_Meal(Customer : PERSON) do
  81.                Put(Customer);
  82.                Put_Line(" is ordering at the Burger Boy");
  83.                delay 0.1 * HOURS;
  84.                Put(Customer);
  85.                Put_Line(" is eating at the Burger Boy");
  86.                delay 0.1 * HOURS;
  87.             end Eat_A_Meal;
  88.          or
  89.             delay 2.1 * HOURS;
  90.             Put_Line("The Burger Boy is closed for the day");
  91.             exit;
  92.          end select;
  93.       end loop;
  94.    end Burger_Boy;
  95.  
  96. begin
  97.    null;
  98. end Meals3;
  99.  
  100.  
  101.  
  102.  
  103. -- Result of execution
  104.  
  105. -- JOHN is ordering at the restaurant
  106. -- JOHN is eating at the restaurant
  107. -- BILL is ordering at the Burger Boy
  108. -- BILL is eating at the Burger Boy
  109. -- JOHN is ordering at the restaurant
  110. -- BILL is ordering at the Burger Boy
  111. -- BILL is eating at the Burger Boy
  112. -- JOHN is eating at the restaurant
  113. -- BILL is ordering at the restaurant
  114. -- BILL is eating at the restaurant
  115. -- The Burger Boy is closed for the day
  116. -- The restaurant is closed for the day
  117.  
  118.