Question: Problem 1 : [ 1 2 pts ] The Metropolitan Transportation Authority ( MTA ) in New York City has introduced a new fare system
Problem :
pts
The Metropolitan Transportation Authority MTA in New York City has introduced a new fare system based on the zones of the subway stations. The city is divided into three zones:
Zone : Manhattan
Zone : Brooklyn and Queens
Zone : The Bronx and Staten Island
The fare rules are as follows:
Traveling within the same zone costs $
Traveling between Zone and Zone costs $
Traveling between Zone and Zone costs $
Traveling between Zone and Zone costs $
The MTA provides a map of stations and their corresponding zones as follows:
tableStationZoneTimes Square,Grand Central,WilliamsburgAstoriaBronx Zoo,Staten Island Terminal,
Define a function calculateFare that takes two arguments:
The starting station a string
The ending station a string
The function should return the total fare based on the zones of the starting and ending stations. Assume that the map of stations and their zones is available within the function using a simple associative map.
Example:
tableStarting Station,Ending Station,Fare $Times Square","Grand Central",Times Square","Williamsburg",Williamsburg"Astoria",Astoria"Bronx Zoo",Grand Central","Staten Island Terminal",
Note: Assume that the input will always contain a valid station name. You do not need to handle for invalid station names.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
