50 lines
2.2 KiB
Markdown
50 lines
2.2 KiB
Markdown
# 1. Goal
|
|
Calculate the toll that a vehicle pays for one journey on a toll road. A billing
|
|
program calls the calculation for each journey. The program needs the toll in
|
|
cents and one reason code for each journey.
|
|
|
|
# 2. Open questions
|
|
None.
|
|
|
|
# 3. Context
|
|
- The interface {{P}}IF_TOLL_PRICER exists in package $TMP. It is active.
|
|
- The interface contains the type TY_JOURNEY for the input, the type TY_RESULT
|
|
for the output, the constant structure C_CLASS with the vehicle classes, the
|
|
constant structure C_REASON with the reason codes, and one method:
|
|
PRICE_JOURNEY IMPORTING is_journey TYPE ty_journey
|
|
RETURNING VALUE(rs_result) TYPE ty_result.
|
|
|
|
# 4. Contract
|
|
- Create the class {{P}}TOLL_PRICER in package $TMP.
|
|
- The class is public, final and has a public constructor without parameters.
|
|
- The class implements {{P}}IF_TOLL_PRICER.
|
|
- Do not add other public methods.
|
|
|
|
# 5. Business rules
|
|
Apply the rules in this sequence. All amounts are in cents. Use integer
|
|
arithmetic and discard remainders.
|
|
1. Convert the vehicle class to upper case. The valid classes are M
|
|
(motorcycle), C (car), V (van) and L (lorry). If the class is not valid,
|
|
return the reason VEHICLE and the amount 0.
|
|
2. The distance must be 1 kilometre or more and 130 kilometres or less. If not,
|
|
return the reason DISTANCE and the amount 0.
|
|
3. The rate for each kilometre is 5 cents for M, 10 cents for C, 18 cents for V
|
|
and 30 cents for L. The toll is the distance multiplied by the rate.
|
|
4. If the toll is below 100 cents, set the toll to 100 cents.
|
|
5. If the vehicle has a transponder, subtract one tenth of the toll from the
|
|
toll. Example: a toll of 1000 cents becomes 900 cents.
|
|
6. If the journey is at night and the vehicle class is L, add one quarter of the
|
|
toll to the toll. Example: a toll of 3000 cents becomes 3750 cents.
|
|
7. Return the reason OK and the toll in the component amount_cents.
|
|
|
|
# 6. Constraints
|
|
- Release target: 8.16 (SAP_BASIS 816).
|
|
- Coding standards: Clean ABAP. Method length below 40 statements. No global
|
|
variables. No comment that restates the code.
|
|
- Out of scope: do not change {{P}}IF_TOLL_PRICER.
|
|
|
|
# 7. Acceptance
|
|
- The class is active and has no syntax error.
|
|
- The hidden tests pass.
|
|
- Write your own ABAP Unit tests for the class.
|