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 bus-bus interchange facility at Tuen Mun Road. Passengers can take a bus route from anywhere to the facility (i.e.,1st trip), then interchange another bus route to reach their destination (i.e.,2nd 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 e-payment method):
1. If the full fare of the 2nd trip is more expensive than the 1st trip, the fare passengers need to pay for the 2nd trip will be the difference between the full fare of the two trips. Or else, passengers do not need to pay for the 2nd trip.
2. If the route name taken in the 1st trip starts with P, e.g., P960, the 2nd trip will be free regardless of the route the passenger takes.
3. The above discount scheme does not apply in the following situations:
(i) The bus route taken in the 1st trip is not operated by the Big Northwest Bus Company.
(ii) The route name taken in the 2nd trip starts with A, e.g., A33X.
(iii) The remaining balance in the passengers Octopus card is less than HK$1 when paying for the 2nd trip.
For situation (i) and (ii), full fare must be paid for the 2nd trip.
For situation (iii), the payment fails and passenger has to pay the 2nd trip by cash.
Task:
Write a program Question1.java that calculates the remaining balance of the passengers Octopus card, after he/she uses it to conduct payment for the 2nd 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 2nd trip.
Assumptions:
1. The company code of the Big Northwest Bus Company is BNB.
2. Length of the route name and the operating company code will not be longer than 4 characters. All English characters involved are capitalized.
3. The remaining balance and full fares of the bus trips must be an integer.
4. All passengers must take the 1st bus trip to enter the interchange facility, and all of them pay the 1st trip successfully by using their Octopus card.
5. There is no other purchase paid by the Octopus card in-between the two trips.
6. The three lines of input are always valid.
Sample Test Cases:
Test Case 1
Input:
8
58M BNB 9
960 BNB 14
Output:
The remaining balance is 3.
Test Case 2
Input:
2
962X CTB 23
961 BNB 14
Output:
The remaining balance is -12.
Test Case 3
Input:
-3
59M BNB 19
961 BNB 24
Output:
The remaining balance is -3.

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!