3.4 KiB
3.4 KiB
1. Goal
Check a booking request for an escape room and calculate the price of the game. The booking program calls the check before it confirms a booking. The check raises a class-based exception for each rule that fails.
2. Open questions
None.
3. Context
- The exception classes {{P}}CX_ESCAPE_ERROR, {{P}}CX_ESCAPE_ROOM, {{P}}CX_ESCAPE_PLAYERS, {{P}}CX_ESCAPE_AGE and {{P}}CX_ESCAPE_TIME exist in package $TMP. They are active.
- {{P}}CX_ESCAPE_ERROR is abstract and inherits from CX_STATIC_CHECK. It has a public constructor with the importing parameter iv_text (TYPE string) and the public read-only attribute mv_text (TYPE string). The constructor writes iv_text to mv_text.
- {{P}}CX_ESCAPE_ROOM, {{P}}CX_ESCAPE_PLAYERS, {{P}}CX_ESCAPE_AGE and {{P}}CX_ESCAPE_TIME inherit from {{P}}CX_ESCAPE_ERROR and add no members.
- The rooms of the escape room operator and their rules are fixed:
- MARS: 2 to 6 players, minimum age 12, 25.00 per player, minimum lead time 2 hours.
- DEEP: 3 to 8 players, minimum age 16, 30.00 per player, minimum lead time 4 hours.
- JUNG: 2 to 4 players, minimum age 8, 22.00 per player, minimum lead time 1 hour.
- BANK: 4 to 10 players, minimum age 18, 35.00 per player, minimum lead time 6 hours.
4. Contract
- Create the class {{P}}ESCAPE_CHECKER in package $TMP.
- The class is public, final, and has a public constructor without parameters.
- The class has these public types:
- TY_ROOM: type c, length 4.
- TY_PRICE: type p, length 8, 2 decimal places.
- The class has one public method: CHECK_BOOKING IMPORTING iv_room TYPE ty_room iv_players TYPE i iv_youngest_age TYPE i iv_lead_hours TYPE i RETURNING VALUE(rv_price) TYPE ty_price RAISING {{P}}CX_ESCAPE_ROOM {{P}}CX_ESCAPE_PLAYERS {{P}}CX_ESCAPE_AGE {{P}}CX_ESCAPE_TIME
- Do not add other public methods.
5. Business rules
Apply the rules in this sequence. Raise the exception of the first rule that fails. Every exception carries a short text in iv_text. The text is free.
- Remove all spaces from iv_room and convert the letters to upper case. The result must be MARS, DEEP, JUNG or BANK. If not, raise {{P}}CX_ESCAPE_ROOM.
- iv_players must be at least the minimum number of players of the room and at most the maximum number of players of the room. If not, raise {{P}}CX_ESCAPE_PLAYERS.
- iv_youngest_age must be at least the minimum age of the room. If not, raise {{P}}CX_ESCAPE_AGE.
- iv_lead_hours must be at least the minimum lead time of the room. If not, raise {{P}}CX_ESCAPE_TIME.
- The price is iv_players multiplied by the price per player of the room. If iv_players equals the maximum number of players of the room, the group gets a discount of 10 %. Return the price with 2 decimal places.
6. Constraints
- Release target: SAP_BASIS 816.
- Coding standards: Clean ABAP. Method length below 40 statements. No global variables. No comment that restates the code. Every ABAP Unit test handles all exceptions that the tested method declares.
- Out of scope: do not change {{P}}CX_ESCAPE_ERROR, {{P}}CX_ESCAPE_ROOM, {{P}}CX_ESCAPE_PLAYERS, {{P}}CX_ESCAPE_AGE and {{P}}CX_ESCAPE_TIME.
7. Acceptance
- The class is active and has no syntax error.
- The class and its test classes have no ATC priority 1 or 2 finding.
- The hidden tests pass.
- Write your own ABAP Unit tests for the class.