Question: Problem 1 : [ 1 2 pts ] The Metropolitan Transportation Authority ( MTA ) in New York City has introduced a new fare system

Problem 1:
[12 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 1: Manhattan
Zone 2: Brooklyn and Queens
Zone 3: The Bronx and Staten Island
The fare rules are as follows:
Traveling within the same zone costs $2.50.
Traveling between Zone 1 and Zone 2 costs $3.50.
Traveling between Zone 1 and Zone 3 costs $4.50.
Traveling between Zone 2 and Zone 3 costs $3.00.
The MTA provides a map of stations and their corresponding zones as follows:
\table[[Station,Zone],[Times Square,1],[Grand Central,1],[Williamsburg,2],[Astoria,2],[Bronx Zoo,3],[Staten Island Terminal,3]]
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:
\table[[Starting Station,Ending Station,Fare ($)],["Times Square","Grand Central",2.5],["Times Square","Williamsburg",3.5],["Williamsburg","Astoria",2.5],["Astoria","Bronx Zoo",3.0],["Grand Central","Staten Island Terminal",4.5]]
Note: Assume that the input will always contain a valid station name. You do not need to handle for invalid station names.
Problem 1 : [ 1 2 pts ] The Metropolitan

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!