Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

code in python 3 def addMinutes(currentTime, minutesPassed): mins=currentTime%100hour=currentTime/1100totalMinutes=mins+60hourtotalMinutes+=minutesPassednewMinutes=totalMinutes%60newhour=totalMinutes//60returnnewHour100+newMinutes # Complete the 'trainschedule' function below. H. * The function is expected to return an INTEGER. #

code in python 3
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
def addMinutes(currentTime, minutesPassed): mins=currentTime%100hour=currentTime/1100totalMinutes=mins+60hourtotalMinutes+=minutesPassednewMinutes=totalMinutes%60newhour=totalMinutes//60returnnewHour100+newMinutes \# Complete the 'trainschedule' function below. H. * The function is expected to return an INTEGER. \# The function accepts following parameters: \# 1. INTEGER_ARRAY arrivalstations H 2. INTEGER_ARRAY arrivaltimes H 3. INTEGER.ARRAY deststations * 4. INTEGER_ARRAY destTimes \# 5. INTEGER timeBtwStations def trainschedule(arrivalstations, arrivaltimes, deststations, destTimes, timeBtwstations); * Write your code here 2. Trains Task The Red Line train is undergoing maintenance causing delays and only has trains running in one direction. The Transit Authority needs to know how many people will be late to work as a result of these changes. You need to give them the total number of people that will be late to work on a given day based on the data they give you. Resident surveys have given us data on people's commutes. Info Passenger info: - Passengers will enter the first train that has capacity that arrives at their station while they are there. - If two passengers arrive at a station at the same time, the passenger listed first will board the train first. - Each passenger will arrive at a specific station (arrivalstations) at a specific time (arrivalTines). Stations are numbered 1 through any unlimited positive integer. - Each passenger will have a destination station (destStations) at which they need to get to before a specific time (destTimes) in order to be on time for work. - This data will be given in 4 list parameters where the index of each list corresponds to the same passenger. Passenger n arrives at station arrivalstations [n] at time arrivaltimes[n] Train info: Train Info: - Trains can hold up to 5 people at a time. - Trains arrive at station 1 every 15 minutes starting at 6:30am - Trains wait for 2 minute at each station before departing, even if there are no passenger to load or unload - The amount of time it takes for a given train to travel from one station to the next will be given by the parameter timeBtwStations. Input - arrivalStationy: List of integers. The nth integer in the list corresponds to the station to which the nth passenger arrives at their station to wait for their train - arrivalTimes: List of integers. The nth integer in the list corresponds to the time at which the nth passenger arrives at their station to wait for their train - destStations: List of integers. The nth integer in the list corresponds to the station which the nth passenger will depart their train - destTimes: List of integers. The nth integer in the list corresponds to the time at which the nth passenger must arrive at their destination station. If the passenger arrives at their destination after their dest time, they will be late for work - timeBtwStations: Integer: the time in minutes that it takes for a train to travel from one station to the next. - All inputs will be sorted, first by station, then by arrival time, in ascending order. - The destination station for any passenger will always be strictly greater than the arrival station - Times will be represented as an integer hhmm, where hh is the hour, and mm is the minutes. - A method addMinutes has been provided to help add times together. Output - Return the numbef of passengers who were late for work Example - arrivalstations =[1,1,1,2] - arrivalTimes =[620,620,620,650] - deststations =[2,2,3,3] - destTimes =[700,700,645,655] - timeBtwStations =5 Timeline: - Time=620: Passengers 1, 2, 3 arrive at station 1 - Time=630: Train 1 arrives at Station 1 and picks up the 2 passengers waiting there. - Time=637: Train 1 arrives at Station 2 and drops off Passengers 1 and 2 . - Time=644: Train 1 arrives at Station 3 and drops off Passenger 3. Train 1 continues with no more passengers to pick up - Time=645: Train 2 arrives at Station 1 and departs - Time =650 : Passenger 4 arrives at Station 2 - Time=652: Train 2 arrives at Station 2 and picks up Passenger 4 - Time=659: Train 2 arrives at Station 3, drops off Passenger 4 , and departs. Passenger 4 is late. There was 1 late passenger (passenger 4 ), return 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 15th International Conference Dasfaa 2010 Tsukuba Japan April 2010 Proceedings Part 1 Lncs 5981

Authors: Hiroyuki Kitagawa ,Yoshiharu Ishikawa ,Wenjie Li ,Chiemi Watanabe

2010th Edition

3642120253, 978-3642120251

More Books

Students also viewed these Databases questions