3.6 KiB
3.6 KiB
1. Goal
A riding stable sells riding lessons. A booking program calls the class {{P}}RIDE_BOOKING for each booking request. The class checks the request and returns the price that one rider pays. The class stops the booking with a class-based exception if the request is not correct.
2. Open questions
None.
3. Context
- The interface {{P}}IF_RIDE_BOOKING is in package $TMP. It is active.
- The interface has these types: TY_DISCIPLINE (character 4), TY_LEVEL (character 1), TY_REASON (character 10), TY_AMOUNT (packed number, length 8, 2 decimal places).
- The interface has these constants: C_DISCIPLINE: DRESSAGE 'DRES', JUMPING 'SHOW', WESTERN 'WEST', VAULTING 'VOLT'. C_LEVEL: BASIC 'B', LIGHT 'L', MEDIUM 'M', ADVANCED 'S'. C_REASON: NAME 'NAME', DISCIPLINE 'DISCIPLINE', LEVEL 'LEVEL', MINUTES 'MINUTES', RIDERS 'RIDERS', SHOW_LEVEL 'SHOW_LEVEL', VOLT_GROUP 'VOLT_GROUP'.
- The interface has one method: BOOK IMPORTING iv_rider_name TYPE string iv_discipline TYPE ty_discipline iv_level TYPE ty_level iv_minutes TYPE i iv_riders TYPE i RETURNING VALUE(rv_price) TYPE ty_amount RAISING {{P}}CX_RIDE_INPUT {{P}}CX_RIDE_LIMIT.
- The exception classes {{P}}CX_RIDE_BOOKING, {{P}}CX_RIDE_INPUT and {{P}}CX_RIDE_LIMIT are in package $TMP. They are active.
- {{P}}CX_RIDE_BOOKING inherits from CX_STATIC_CHECK. It has the type TY_REASON (character 10), the read-only attribute REASON of type TY_REASON and the constructor with the importing parameter IV_REASON of type TY_REASON.
- {{P}}CX_RIDE_INPUT and {{P}}CX_RIDE_LIMIT inherit from {{P}}CX_RIDE_BOOKING. They add nothing.
4. Contract
- Create the class {{P}}RIDE_BOOKING in package $TMP.
- The class is public, final, and has a public constructor without parameters.
- The class implements {{P}}IF_RIDE_BOOKING.
- Do not add other public methods.
5. Business rules
Apply the rules in this sequence. Raise the exception of the first rule that fails.
- If the rider name is empty, raise {{P}}CX_RIDE_INPUT with the reason NAME.
- The discipline must be DRES, SHOW, WEST or VOLT. Else raise {{P}}CX_RIDE_INPUT with the reason DISCIPLINE.
- The level must be B, L, M or S. Else raise {{P}}CX_RIDE_INPUT with the reason LEVEL.
- The number of minutes must be 30, 60, 90 or 120. Else raise {{P}}CX_RIDE_INPUT with the reason MINUTES.
- The number of riders must be between 1 and 6. Else raise {{P}}CX_RIDE_INPUT with the reason RIDERS.
- Show jumping (SHOW) is only for the levels M and S. Else raise {{P}}CX_RIDE_LIMIT with the reason SHOW_LEVEL.
- Vaulting (VOLT) is only for a group lesson with 3 or more riders. Else raise {{P}}CX_RIDE_LIMIT with the reason VOLT_GROUP.
- Calculate the price that one rider pays: a. The base rate for 30 minutes: DRES 20, SHOW 25, WEST 18, VOLT 15. b. The level surcharge for 30 minutes: B 0, L 2, M 4, S 6. c. The gross price = (base rate + level surcharge) * (minutes / 30). d. The group discount: 1 or 2 riders 0 percent, 3 or 4 riders 20 percent, 5 or 6 riders 40 percent. e. The price = gross price * (100 - group discount) / 100.
6. Constraints
- Release target: SAP_BASIS 816 (ABAP Platform 2025).
- 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_RIDE_BOOKING, {{P}}CX_RIDE_BOOKING, {{P}}CX_RIDE_INPUT and {{P}}CX_RIDE_LIMIT.
7. Acceptance
- The class is active and has no syntax error.
- The hidden tests pass.
- Write your own ABAP Unit tests for the class.