'''
Ensure correct tab spacing before you run the program
'''
import time
from threading import Thread, Lock
class Clock:
#currentTime = 0;
def run(self):
self.currentTime = 0;
while(True):
time.sleep(1)
self.currentTime += 1
def now(self):
return self.currentTime
clock = Clock()
class Assistant:
def __init__(self, pStart, pEnd):
self.StartTime = pStart
self.EndTime = pEnd
self.Speed = 5
self.Table = [ None, None, None ]
self.Arrivals = []
self.CurrentlyHelping = None
self.myIdleTime = 0
self.mutex = Lock()
def run(self):
self.helpStudent()
def helpStudent(self):
while(clock.now() < self.EndTime):
if (len(self.Arrivals) ==0 ):
time.sleep(1)
self.myIdleTime += 1
else:
earliest = self.Arrivals.pop(0)
self.CurrentlyHelping = self.Table[earliest]
while(self.CurrentlyHelping.getTimeRequired() > 0):
time.sleep(1)
self.CurrentlyHelping = None
def getTable(self):
return self.Table
def getEmptySlot(self):
try:
slot = self.Table.index(None)
except (ValueError):
slot = None
return slot
def getCurrentlyHelping(self):
return self.CurrentlyHelping
def fillSlot(self, pSlot, pStudent):
self.mutex.acquire()
if (self.Table[pSlot] is None):
self.Table[pSlot] = pStudent
self.Arrivals.append(pSlot)
self.mutex.release()
return True
else:
self.mutex.release()
return False
def getIdleTime(self):
return myIdleTime
def getArrivals(self):
return self.Arrivals
#End of TA
resourceCentre = []
waitingResources = 0
totalWaitTime = 0
tableWaitTime = 0
waitingAtTable = 0
class Student:
def __init__(self, pID, pTimeRequired, pSeekHelpAt,pTA):
self.ID = pID
self.TimeReq = pTimeRequired
self.ApproachTA = pSeekHelpAt
self.TA = pTA
self.myArrivalTime = None
self.mySlot = None
self.myWaitTime = 0
self.waiting = False
def run(self):
while(clock.now() < self.ApproachTA):
time.sleep(1)
self.seekHelp()
def waitInResourceQueue(self):
global waitingResources
self.waiting = True;
waitingResources += 1
while(resourceCentre.index(self) > 0):
time.sleep(1)
self.myWaitTime += 1
def seekHelp(self):
if (self.TA.getEmptySlot() is None):
resourceCentre.append(self)
self.waitInResourceQueue()
self.mySlot = self.TA.getEmptySlot()
while(self.mySlot is None or not self.occupySlot()):
time.sleep(1)
self.mySlot = self.TA.getEmptySlot()
if(self.TA.getCurrentlyHelping() != self):
self.solveOnYourOwn()
while(self.TimeReq > 0):
time.sleep(1)
self.TimeReq -= 1
self.leaveSlot()
def solveOnYourOwn(self):
global waitingAtTable
global tableWaitTime
val = 1
waitingAtTable += 1
while (self != self.TA.getCurrentlyHelping()):
time.sleep(1)
tableWaitTime += 1
if (val == 0):
self.TimeReq -= 1
if (self.TimeReq == 0):
return
val = (val + 1)%3
def occupySlot(self):
global totalWaitTime
if (not self.TA.fillSlot(self.mySlot, self)):
self.mySlot = None
return False
else:
if (self.waiting):
resourceCentre.pop(0)
totalWaitTime += self.myWaitTime
self.myArrivalTime = clock.now()
return True
def getArrivalTime(self):
return self.myArrivalTime
def getTimeRequired(self):
return self.TimeReq
def leaveSlot(self):
tbl = self.TA.getTable()
tbl[self.mySlot] = None
def getWaitTime(self):
return self.myWaitTime
#End of Student
def main():
tClock = Thread(name="clock", target=clock.run)
tClock.start()
print("Please wait 10 seconds for the output")
TA = Assistant(0, 10)
tTA = Thread(name="ta", target=TA.run)
tTA.start()
myClass = []
for i in range(0,25):
#pID, pTimeRequired, pSeekHelpAt,pTA
obj = Student(i, 4+i%5, 3+i+i, TA)
student = Thread(target = obj.run)
student.start();
myClass.append(student);
tTA.join()
#for(student in myClass):
# student.join()
global totalWaitTime, waitingResources, resourceCentre, waitingAtTable, tableWaitTime, resourceCentre
print("Average wait of resource line: ", totalWaitTime/waitingResources)
print("Total students remaining in resource Line: ", len(resourceCentre))
print("Average wait of tables: ", tableWaitTime/waitingAtTable)
print("Number of students TA was not able to help: ", len(resourceCentre) + len(TA.getArrivals()))
main()
1 Problems (PY 1. Write a program to simulate a very busy TA in office hours,...
Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...
art 250 Choose the best answer of both hands at the same time is A. flow process chart simultaneous-motion (SIMO) chart 2 The best chart used to analyze the Body is called B. Operations charts D. None of the above 3. In a stopwatch time study, the average time it takes a given worker to perform a task a certain number of times is the: A. Observed time B. Normal time C. Standard time D. Performance rating time Labor Standards...
Java Project For this assignment, you will 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 instead include a single add method...
write up an essay on the problems in budgeting derived from the articles (i do Upvote the answers ) Why Budgeting Kills Your Company HBSWK Pub. Date: Aug '1 1, 2003 Why doesn't the budget process work? Read what experts say about not only changing your budgeting process, but whether your company should dispense with budgets entirely. by Loren Gary The average billion-dollar company spends as many as 25,000 person-days per year putting together the budget. If this all paid...
Houghton Refrigeration Company builds refrigerators for large appliance companies. It employs about 300 people, mostly assembly -line workers, and is located in a small rural town in Ohio. The company typically builds, on a contract basis, chest freezers and small bar refrigerators. On occasion, however, it also builds standard size refrigerators. The president of the company is a former engineer, as are most of the other executives. These individuals are very knowledgeable about engineering but have received little training in...
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...
Read the case and Summarizes the situation as you see it. Describes what Organizational Development is and its core values Good morning. Northern County Legal Services," Christina said. "How can I help you? Yes, I see. Okay, why don't I schedule a time for you to stop by and talk with one of us about your situation and we can see how we can help? I'm free on the 12th at 3:30 p.m. Does that work for you? Excellent. And...
BUS:Leading Strategic Change within Organization Case Study 'l: Analyzing Opportunities for Organization Development Work at Northern County Lega! Services Read the Northern County Legal Services "Good morning. Northern County Legal Services," Christina said. "How can I help you? Yes, I see. okay, why don't I schedule a time for you to stop by and talk with one of us about your situation and we can see how we can help? l'm free on the l2th at 3:30 p.m. Does that...
***Please help with this Research Paper. Following points are to be covered in the research paper with as much detail as possible:1. Case Overview - Concise summary of the main issues of the case. Please ensure all issues are identified.2. Analysis - External and internal analysis of the case issues. Application of evidence based development of course concepts, research and applicable legislation.3. Implementation & Recommendations - Detailed application of appropriate legislation to form recommendations. ***Case Study: "Found: An Unsigned Card"Tara...
cs55(java) please
Part 1: You are a programming intern at the student transfer counselor's office. Having heard you are taking CS 55, your boss has come to ask for your help with a task. Students often come to ask her whether their GPA is good enough to transfer to some college to study some major and she has to look up the GPA requirements for a school and its majors in a spreadsheet to answer their question. She would like...