Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Write a program that tracks a drive through at Four Friends Fries Have a queue for the line of cars Have a stack of cooked fries for serving  Simulate 60 minutes worth of time at the drive...

1 answer below »
Write a program that tracks a drive through at Four Friends Fries
Have a queue for the line of cars
Have a stack of cooked fries for serving
 Simulate 60 minutes worth of time at the drive thru.
Every minute, there is a 1/3 chance of a car showing up when a car gets to the front of the queue, it orders 1-6 orders of fries randomly the fry stack can have up to 8 fries at a time, track the 'time' they are done cooking.  if a fry is older than 10 minutes, it can't be served you can be cooking up to 4 orders of fries at a time in the frier, they take 2 minutes to cook so for each 'minute' figure out if a new car a
ives in the drive through take any cooked fries out of the frier and add to the cooked fry stack ( with time done cooking ) take the order from the front car possibly add more fries to the frier to cook assume each order of fries costs $.5, and is sold for $1.
track total profit/loss after 60 minutes
import random
import time
class Fry:
def __init__(self, cook_time):
XXXXXXXXXXself.cook_time = cook_time
class Car:
def __init__(self, order_size):
XXXXXXXXXXself.order_size = order_size
def main():
# Start with an empty queue and stack
queue = []
stack = []
# Track the time and profit
cu
ent_time = 0
profit = 0
# Cook up to 4 orders of fries at a time
frier_size = 4
frier = []
# A car has a 1/3 chance of a
iving each minute
a
ival_chance = 1 / 3
# Each order of fries takes 2 minutes to cook
fry_cook_time = 2
# Each order of fries costs $0.5 and is sold for $1
fry_cost = 0.5
fry_price = 1
while cu
ent_time < 60:
XXXXXXXXXXcu
ent_time += 1
# Check if a new car a
ives
XXXXXXXXXXif random.uniform(0, 1) < a
ival_chance:
XXXXXXXXXXorder_size = random.randint(1, 6)
XXXXXXXXXXqueue.append(Car(order_size))
# Remove any cooked fries from the frier and add them to the stack
XXXXXXXXXXfor fry in frier:
XXXXXXXXXXfry.cook_time -= 1
XXXXXXXXXXif fry.cook_time == 0:
XXXXXXXXXXstack.append(fry)
XXXXXXXXXXfrier = [fry for fry in frier if fry.cook_time != 0]
# Cook more fries if there's room in the frie
XXXXXXXXXXif len(frier) < frier_size:
XXXXXXXXXXif len(queue) > 0 and len(stack) >= queue[0].order_size:
XXXXXXXXXXnew_fries = []
XXXXXXXXXXfor i in range(min(frier_size - len(frier), queue[0].order_size)):
XXXXXXXXXXfry = stack.pop()
XXXXXXXXXXnew_fries.append(Fry(fry_cook_time))
XXXXXXXXXXfrier.extend(new_fries)
# Serve the front car if their order is ready
XXXXXXXXXXif len(queue) > 0 and len(stack) >= queue[0].order_size:
XXXXXXXXXXorder_size = queue.pop(0).order_size
XXXXXXXXXXfor i in range(order_size):
XXXXXXXXXXstack.pop()
XXXXXXXXXXprofit += fry_price * order_size - fry_cost * order_size
# Remove any fries that are older than 10 minutes
XXXXXXXXXXstack = [fry for fry in stack if cu
ent_time - fry.cook_time <= 10]
print("Total profit after 60 minutes: $" + str(profit))
if __name__ == '__main__':
main()
Answered Same Day Feb 14, 2023

Solution

Vedant answered on Feb 14 2023
30 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here