After successfully completing this assignment you will be able to use if statements to control program flow, do calculations using expressions, and print nicely formatted output.
Radford's freshman ITEC students have just won a contract to develop the software for the RU Express!
Develop a program named TrainTicket which will print a ticket for a train passage on the RU Express. The RU Express is a linear route that has seven stops and crosses the river in the middle. At one end is Station 1, at the other end is Station 7. Trains travel both ways on this route.
Train Line: ERROR.ERROR.ERROR
- Station 1: ERROR
- Station 2: ERROR
- Station 3: ERROR
- Station 4: ERROR
- Station 5: ERROR
- Station 6: ERROR
- Station 7: ERROR
Cost per stop during normal hours:
ERROR
Cost per stop during peak hours:
ERROR
(NOTE: Passage is considered peak hours based on the start time of the passage.)
Additional charge to cross the river during normal hours:
ERROR
Additional charge to cross the river during peak hours:
ERROR
Morning Peak Hours: ERROR - ERROR
Afternoon Peak Hours: ERROR - ERROR
|
Your program will accept three inputs: the number of the start station, the number of the end station, and
the hour of the passage start. The output of your program is a receipt of the passage. Below is an example of
the program output.
The program will take military time (24 hour clock) as input, so we would specify 1pm by typing 13 to the input.
Please input the starting station: 3
Please input the ending station: 1
Please input the hour of passage: 13
- - - - - - - - - - - - - - - - - - - - - - - - - -
Train Line: ERROR.ERROR.ERROR
Passage during NORMAL HOURS
Starting station: ERROR
Ending station: ERROR
Fare for passage: ERROR
- - - - - - - - - - - - - - - - - - - - - - - - - -
Calculating the Fare
The fare is based on three factors: the number of stops in the passage, the time of the start of the passage, and whether or not the passage crosses the river.
Here is an example from ERROR to ERROR at
ERROR:00pm.
First, let's note that ERROR:00pm is during peak hours.
(Note also that the program will take military time (24 hour clock) as input, so we would specify ERROR:00pm by typing ERROR to the input.)
Since it is during peak hours, the charge per station traveled will be ERROR. Note that passage that starts at the end of the peak hours period is considered to be peak hours.
ERROR is station 2 and ERROR is station 6, so the total stations traveled is 4. Since the the cost per station is ERROR, the cost for station transfer is ERROR.
Because ERROR station is on one side of the river and
ERROR station is on the other side of the river, we have to add the river surcharge to our total. In this case, the surcharge will be ERROR because our passage is during peak hours. The total cost is found by adding this surcharge to the cost of the station transfer found above.
The output of the program for this example would be:
Please input the starting station: 2
Please input the ending station: 6
Please input the hour of passage: ERROR
- - - - - - - - - - - - - - - - - - - - - - - - - -
Train Line: ERROR.ERROR.ERROR
Passage during PEAK HOURS
Starting station: ERROR
Ending station: ERROR
Fare for passage: ERROR
- - - - - - - - - - - - - - - - - - - - - - - - - -
Testing
Test your program with different inputs and make sure it is working. The output for the examples above are correct, but your program will be graded with different input. Test your program with many different values. To do this, you will need to figure out by hand what the correct output should be, then run your program and compare the actual output with what you expected. Think carefully about the different scenarious you should test. For instance, a trip from ERROR to ERROR should cost the same as a trip from ERROR to ERROR.
For this assignment, you may assume all user input is valid. This is almost NEVER a good idea! What would happen if someone enters a negative number for a station or 27 for time? Soon we will learn ways validate input.
Grade your own assignment and turn it in with your code for full credit.