Question

Goal: Write a Python program to implement an airport take-offldeparture simulator Proiect: Consider the following tables whic
From the above three queues (one for each airline), flights will be added to a separate runway queue as aircraft exit their g
All four queues (American, Delta, Southwest and the runway) MUST be implemented using a linked list . You may work individual
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import random
import time

class Node:
def __init__(self, data):
self.data = data
self.next = None

class Queue:
def __init__(self):
self.head = None
self.last = None

def enqueue(self, data):
if self.last is None:
self.head = Node(data)
self.last = self.head
else:
self.last.next = Node(data)
self.last = self.last.next

def dequeue(self):
if self.head is None:
return None
else:
to_return = self.head.data
self.head = self.head.next
return to_return

def getdata(self):
temp = self.head
Data = list()
while temp is not None:
Data.append(temp.data)
# print(temp.data)
temp = temp.next

return Data

def sizequeue(self):
temp = self.head
count = 0
while temp is not None:
count = count + 1
temp = temp.next

return count

def top(self):
return self.head.data

American = Queue()
Delta = Queue()
Southwest = Queue()
Runway = Queue()

American.enqueue(["American",127,"DCA",10])
American.enqueue(["American",322,"BUF",11])
American.enqueue(["American",233,"FLL",12])
American.enqueue(["American",742,"LAX",13])
American.enqueue(["American",112,"CAE",14])
American.enqueue(["American",437,"LGA",15])

Delta.enqueue(["Delta",221,"SFO",20])
Delta.enqueue(["Delta",348,"DET",21])
Delta.enqueue(["Delta",765,"CVG",22])
Delta.enqueue(["Delta",612,"SAN",23])
Delta.enqueue(["Delta",148,"FLL",24])

Southwest.enqueue(["Southwest",345,"LGA",40])
Southwest.enqueue(["Southwest",657,"PHL",41])
Southwest.enqueue(["Southwest",211,"BOS",42])
Southwest.enqueue(["Southwest",324,"SFO",43])
Southwest.enqueue(["Southwest",367,"SAN",44])
Southwest.enqueue(["Southwest",311,"LAX",45])
Southwest.enqueue(["Southwest",375,"FLL",46])


def Every2sec():
x = random.random()

Asize = American.sizequeue()
Dsize = Delta.sizequeue()
Ssize = Southwest.sizequeue()

if Asize == 0 and Dsize == 0 and Ssize == 0:
return False
if Asize and Dsize and Ssize:
if x >= 0 and x <= .33:
a = American.dequeue()
elif x > .33 and x <= .67:
a = Delta.dequeue()
else:
a = Southwest.dequeue()
else:
if Asize and Dsize:
if x >= 0 and x <= .5:
a = American.dequeue()
else:
a = Delta.dequeue()
elif Dsize and Ssize:
if x >= 0 and x <= .5:
a = Delta.dequeue()
else:
a = Southwest.dequeue()
elif Asize and Ssize:
if x >= 0 and x <= .5:
a = American.dequeue()
else:
a = Southwest.dequeue()
else:
if Asize:
a = American.dequeue()
elif Dsize:
a = Delta.dequeue()
else:
a = Southwest.dequeue()

print("Flight " + str(a[1]) + " of " + str(a[0]) + " airlines is added to Runway Queue ")
Runway.enqueue(a)

def Every4sec_takeoff():
  
y = random.random()

if y >= 0 and y <= .5:
a = Runway.dequeue()
print("Flight " + str(a[1]) + " of " + str(a[0]) + " airlines took off")
else:
a = Runway.top()
print("Flight " + str(a[1]) + " of " + str(a[0]) + " airlines is waiting")

if Runway.sizequeue() == 0:
print("All flights have taken off")
return True
Data = Runway.getdata()

print()
print("List of all flight currently in Runway queue")
print("###################################")
print("Airlines","Flight#","Destination","Gate#")
for i in Data:
print(str(i[0]) + " " + str(i[1]) + " " + str(i[2])+ " " +str(i[3]))
print("-----------------------------------")
return False

def Every4sec_cancel():
z = random.randint(1,100) / 100
a = None
if z >= 0 and z <= .1:
if American.sizequeue() == 0:
print("American airline queue Empty, no need to cancel a flight")
else:
a = American.dequeue()

if z >= .50 and z <= .60:
if Delta.sizequeue() == 0:
print("Delta airline queue Empty, no need to cancel a flight")
else:
a = Delta.dequeue()

if z >= .80 and z <= .90:
if Southwest.sizequeue() == 0:
print("Southwest airline queue Empty, no need to cancel a flight")
else:
a = Southwest.dequeue()

if a is not None:
print(str(a[0]) + " airlines flight no " + str(a[1]) + " travelling to " + str(a[2]) + " is cancelled")

while True:
  
time.sleep(2)
Every2sec()

time.sleep(2)
Every2sec()
if Every4sec_takeoff() == True:
break;
Every4sec_cancel()

Add a comment
Know the answer?
Add Answer to:
Goal: Write a Python program to implement an airport take-offldeparture simulator Proiect: Consider the following tables...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • For this lab you will write a Java program that plays a simple Guess The Word...

    For this lab you will write a Java program that plays a simple Guess The Word game. The program will prompt the user to enter the name of a file containing a list of words. These words mustbe stored in an ArrayList, and the program will not know how many words are in the file before it starts putting them in the list. When all of the words have been read from the file, the program randomly chooses one word...

  • What happened on United flight 3411?What service expectations do customers have of airlines such ...

    What happened on United flight 3411?What service expectations do customers have of airlines such as United and How did these expectations develop over time? Thank You! In early April 2017, United Airlines (United), one of the largest airlines in the world, found itself yet again in the middle of a service disaster this time for forcibly dragging a passenger off an overbooked flight. The incident was to become a wake-up call for United, forcing it to ask itself what to...

  • Use program control statements in the following exercises: Question 1 . Write pseudocode for the following:...

    Use program control statements in the following exercises: Question 1 . Write pseudocode for the following: • Input a time in seconds. • Convert this time to hours, minutes, and seconds and print the result as shown in the following example: 2 300 seconds converts to 0 hours, 38 minutes, 20 seconds. Question 2. The voting for a company chairperson is recorded by entering the numbers 1 to 5 at the keyboard, depending on which of the five candidates secured...

  • Python program This assignment requires you to write a single large program. I have broken it...

    Python program This assignment requires you to write a single large program. I have broken it into two parts below as a suggestion for how to approach writing the code. Please turn in one program file. Sentiment Analysis is a Big Data problem which seeks to determine the general attitude of a writer given some text they have written. For instance, we would like to have a program that could look at the text "The film was a breath of...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

  • The following are screen grabs of the provided files Thanks so much for your help, and have a n...

    The following are screen grabs of the provided files Thanks so much for your help, and have a nice day! My Java Programming Teacher Gave me this for practice before the exam, butI can't get it to work, and I need a working version to discuss with my teacher ASAP, and I would like to sleep at some point before the exam. Please Help TEST QUESTION 5: Tamagotchi For this question, you will write a number of classes that you...

  • Discussion questions 1. What is the link between internal marketing and service quality in the ai...

    Discussion questions 1. What is the link between internal marketing and service quality in the airline industry? 2. What internal marketing programmes could British Airways put into place to avoid further internal unrest? What potential is there to extend auch programmes to external partners? 3. What challenges may BA face in implementing an internal marketing programme to deliver value to its customers? (1981)ǐn the context ofbank marketing ths theme has bon pururd by other, nashri oriented towards the identification of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT