Area 06 · Control structures
Jeepney fare calculator
Compute fares for a line of passengers under a practice fare table, until the conductor enters 0.
- Spec no.
- HO-11
- Level
- Warm-up
- Time box
- 45 min
- Reference
- Java · C#
- Grading
- Self-assessed · rubric is ours, not DICT's
01 Coverage
| Area | Sub-skills practised | Role |
|---|---|---|
| 01 Data manipulation | Validation | Also |
| 06 Control structures | Conditional, Iteration | Primary |
Sign up to start coding practice
Read the task freely. An account is required before editing and running a solution. Code runs also need an internet connection.
Sign up or sign in02 Requirements
- Practice fare table (made up, not an LTFRB fare matrix): ₱15.00 covers the first 4 km; each started kilometre after that adds ₱2.00.
- Categories: R regular, S student, E senior citizen, D person with disability. S, E and D get 20% off.
- Each line is km category. km must be greater than 0 and at most 50. Print Invalid distance: x or Invalid category: x and continue.
- Print km to one decimal, the category and the fare to two decimals.
- A line of 0 ends input. Print Passengers: n Total: x.xx (two spaces before Total).
03 Input and output
- Lines of km category
- 0 to finish
- One line per passenger or error
- Summary line
3 R
4.5 S
10 E
-2 R
7 X
60 R
03.0 km R: 15.00
4.5 km S: 13.60
10.0 km E: 21.60
Invalid distance: -2
Invalid category: X
Invalid distance: 60
Passengers: 3 Total: 50.20Match the sample exactly first, then write at least two test inputs of your own.
04 Edge cases to test
- Exactly 4 km (no extra)
- 4.1 km (one extra kilometre)
- 60 km
- A missing category
05 Starter outline and hints
loop: read line; if 0 → breakvalidate km, categoryextra = ceil(max(0, km − 4)); fare = 15 + 2·extra; discount if S/E/Dprint; count; total
Hint 1
Use the decimal type in C#; in Java, round each fare to cents before adding.
06 Practice rubric
| Criterion | Sub-skills | Look for | Pts |
|---|---|---|---|
| Fare rule | Conditional | Ceiling for started kilometres; discount applied after the distance charge. | 40 |
| Loop and sentinel | Iteration | Stops on 0; keeps a running total and count of valid passengers only. | 25 |
| Validation | Validation | Distance and category errors reported separately. | 20 |
| Output | Conditional | Decimals and spacing exactly as in the sample. | 15 |
| Total | 100 | ||
Our own weighting for practice. It is not the DICT scoring scheme.
07 Self-check
Tick only what you have verified by running your own program.
Loading saved checks…
08 Reference solution
Both versions compiled and reproduced the sample output on Java 21 and .NET 8 when this site was built. Reference solutions are in Java and C#. The 2023 FAQ copy also lists C, C++ and Visual Basic 6.0 / .NET; the same structure carries over, but you will need your language's own file and database APIs.
Try the whole brief first. The reference is one correct approach, not the only one, and reading it early removes most of the practice value.
09 Exam-day habits
- Work without internet search to simulate exam conditions.
- Type the sample input yourself and compare your output line by line before you look at the reference.