Question: Background: The government has just constructed a bus - bus interchange facility at Tuen Mun Road. Passengers can take a bus route from anywhere to
Background:
The government has just constructed a busbus interchange facility at Tuen Mun Road. Passengers can take a bus route from anywhere to the facility iest trip then interchange another bus route to reach their destination iend trip
To encourage passengers interchanging routes that BNB operates in this facility, the company has set up the following discount scheme for passengers who pay both trips by Octopus card an epayment method:
If the full fare of the nd trip is more expensive than the st trip, the fare passengers need to pay for the nd trip will be the difference between the full fare of the two trips. Or else, passengers do not need to pay for the nd trip.
If the route name taken in the st trip starts with P eg P the nd trip will be free regardless of the route the passenger takes.
The above discount scheme does not apply in the following situations:
i The bus route taken in the st trip is not operated by the Big Northwest Bus Company.
ii The route name taken in the nd trip starts with A eg AX
iii The remaining balance in the passengers Octopus card is less than HK$ when paying for the nd trip.
For situation i and ii full fare must be paid for the nd trip.
For situation iii the payment fails and passenger has to pay the nd trip by cash.
Task:
Write a program Questionjava that calculates the remaining balance of the passengers Octopus card, after heshe uses it to conduct payment for the nd trip on any BNBs bus routes.
The program should take in three lines of input with the following format:
The program should output the remaining balance of the passengers Octopus card after paying for the nd trip.
Assumptions:
The company code of the Big Northwest Bus Company is BNB
Length of the route name and the operating company code will not be longer than characters. All English characters involved are capitalized.
The remaining balance and full fares of the bus trips must be an integer.
All passengers must take the st bus trip to enter the interchange facility, and all of them pay the st trip successfully by using their Octopus card.
There is no other purchase paid by the Octopus card inbetween the two trips.
The three lines of input are always valid.
Sample Test Cases:
Test Case
Input:
M BNB
BNB
Output:
The remaining balance is
Test Case
Input:
X CTB
BNB
Output:
The remaining balance is
Test Case
Input:
M BNB
BNB
Output:
The remaining balance is
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
