# L-31 MCS 275 Wed 29 Mar 2017 : fastfood.py
"""
Simulation of fastfood restaurant.
The number of threads is determined by the user.
"""

from threading import Thread
from time import sleep
from random import randint

class Customer(Thread):
    """
    Customer orders food and eats.
    """
    def __init__(self, t):
        """
        Initializes customer with name t,
        generates waiting and eating time.
        """
        Thread.__init__(self, name=t)
        self.wait = randint(1, 6)
        self.eat = randint(1, 6)

    def run(self):
        """
        Customer waits for order and eats,
        writes three messages.
        """
        name = self.getName()
        print(name + ' is waiting for %d time units' % self.wait)
        sleep(self.wait)
        print(name + ' waited %d time units' % self.wait)
        sleep(self.eat)
        print(name + ' ate for %d time units' % self.eat)

def main():
    """
    Defines and starts threads.
    """
    nbr = int(input('give #customers : '))
    threads = []
    for i in range(nbr):
        prompt = 'name of customer %d : ' % i
        name = input('  ' + prompt)
        threads.append(Customer(name))
    print("starting the simulation")
    for customer in threads:
        customer.start()
    print("simulation has started")

if __name__ == "__main__":
    main()
