Files

3.0 KiB

1. Goal

A car park operator calculates the parking fee of a car. The calculation uses the entry time and the exit time of the car. A payment terminal calls the calculation before it charges the driver. The terminal needs the fee and a reason code for each parking event.

2. Open questions

None.

3. Context

  • The interface {{P}}IF_PARK_FEE exists in package $TMP. It is active.
  • The interface contains the type TY_AMOUNT (a packed number, length 8, 2 decimals), the type TY_REASON (a character field, length 10), the structure TY_RESULT with the components REASON (TY_REASON) and FEE (TY_AMOUNT), and the constant structure C_REASON with the components OK, BAD_TIME and TOO_LONG.
  • The interface contains one method: CALCULATE IMPORTING iv_entry_date TYPE d iv_entry_time TYPE t iv_exit_date TYPE d iv_exit_time TYPE t iv_lost_ticket TYPE abap_bool iv_discount TYPE abap_bool RETURNING VALUE(rs_result) TYPE ty_result.

4. Contract

  • Create the class {{P}}PARK_FEE_CALCULATOR in package $TMP.
  • The class is public and final. It has a public constructor without parameters.
  • The class implements the interface {{P}}IF_PARK_FEE.
  • Do not add other public methods.

5. Business rules

The method CALCULATE applies the rules in this sequence. It returns the reason and the fee of the first rule that applies.

  1. The duration is the number of whole minutes between the entry and the exit. Ignore the seconds of the two time fields. Example: the entry 10:00:30 and the exit 10:01:20 give the duration 1 minute. The entry 10:00:00 and the exit 10:30:00 give the duration 30 minutes.
  2. If the exit is before the entry, return the reason BAD_TIME and the fee 0.00.
  3. If the duration is more than 43200 minutes, return the reason TOO_LONG and the fee 0.00.
  4. If the ticket is lost (iv_lost_ticket = abap_true), the fee is 45.00 and the reason is OK. Rules 5 to 9 do not apply.
  5. If the duration is 15 minutes or less, the fee is 0.00 and the reason is OK.
  6. If the entry date is a Sunday, the fee is 0.00 and the reason is OK.
  7. Else the fee is the number of started hours multiplied by 2.50. A started hour is a full hour or a part of an hour. Example: 61 minutes are 2 started hours and give the fee 5.00. 30 minutes are 1 started hour and give the fee 2.50.
  8. If the driver uses the discount card (iv_discount = abap_true), reduce the fee by 25 percent. Round the result to 2 decimals, half up. Example: the fee 5.00 becomes 3.75. The fee 2.50 becomes 1.88.
  9. The fee never exceeds 60.00. If the fee is higher, it is 60.00.
  10. The reason is OK.

6. Constraints

  • Release target: 8.16.
  • Coding standards: Clean ABAP. Keep every method below 40 statements. Do not use global variables. Do not write comments that restate the code.
  • Out of scope: do not change the interface {{P}}IF_PARK_FEE.

7. Acceptance

  • The class is active and has no syntax error.
  • The hidden tests pass.
  • Write your own ABAP Unit tests for the class.