3.6 KiB
3.6 KiB
1. Goal
Check a hot-air balloon flight before the launch. The flight office calls the check for each planned flight. The check must stop a flight when a limit is exceeded. The caller needs one exception for each reason.
2. Open questions
None.
3. Context
- The exception class {{P}}CX_BALLOON_FLIGHT exists in package $TMP. It is active. It inherits from CX_STATIC_CHECK. It has the public read-only attribute MV_TEXT (type string) and a constructor with the importing parameter IV_TEXT (type string). The constructor writes IV_TEXT to MV_TEXT.
- The flight office knows four figures of a flight: the number of passengers, the total take-off weight in kilograms, the wind speed in kilometres per hour, and the height of the cloud base in metres.
4. Contract
- Create the class {{P}}BALLOON_CHECKER in package $TMP.
- The class is public and final. It can be created without constructor parameters.
- The class has the public method CHECK_FLIGHT with these parameters:
- importing IV_PASSENGERS type i
- importing IV_WEIGHT_KG type i
- importing IV_WIND_KMH type i
- importing IV_CLOUD_BASE_M type i
- returning RV_FREE_KG type i
- raising {{P}}CX_BALLOON_FLIGHT
- Do not add other public methods.
- Create these exception classes in package $TMP. Each class inherits from
{{P}}CX_BALLOON_FLIGHT.
- {{P}}CX_BALLOON_CREW with the constructor importing IV_PASSENGERS type i and IV_LIMIT type i.
- {{P}}CX_BALLOON_WEIGHT with the constructor importing IV_WEIGHT_KG type i and IV_LIMIT_KG type i.
- {{P}}CX_BALLOON_WIND with the constructor importing IV_WIND_KMH type i and IV_LIMIT_KMH type i.
- {{P}}CX_BALLOON_CLOUD with the constructor importing IV_CLOUD_BASE_M type i and IV_LIMIT_M type i.
- Each constructor writes the message text to MV_TEXT. Rule 1 to rule 4 of the business rules give the text of each exception.
5. Business rules
The method CHECK_FLIGHT applies the rules in this sequence. It raises the exception of the first rule that fails. If no rule fails, the method returns the free payload.
- Passengers. The limit is 8. If IV_PASSENGERS is greater than 8, raise {{P}}CX_BALLOON_CREW. The message text is "Passengers exceeds the limit ". Example: 12 passengers give the text "Passengers 12 exceeds the limit 8".
- Weight. The limit is 640 kilograms. If IV_WEIGHT_KG is greater than 640, raise {{P}}CX_BALLOON_WEIGHT. The message text is "Weight kg exceeds the limit kg". Example: 700 kilograms give the text "Weight 700 kg exceeds the limit 640 kg".
- Wind. The limit is 18 kilometres per hour. If IV_WIND_KMH is greater than 18, raise {{P}}CX_BALLOON_WIND. The message text is "Wind km/h exceeds the limit km/h". Example: 25 kilometres per hour give the text "Wind 25 km/h exceeds the limit 18 km/h".
- Cloud base. The limit is 300 metres. If IV_CLOUD_BASE_M is less than 300, raise {{P}}CX_BALLOON_CLOUD. The message text is "Cloud base m is below the limit m". Example: 200 metres give the text "Cloud base 200 m is below the limit 300 m".
- Free payload. If no rule fails, the free payload is 640 minus IV_WEIGHT_KG. Return the free payload in RV_FREE_KG.
6. Constraints
- Release target: ABAP Platform 2025 (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}}CX_BALLOON_FLIGHT.
7. Acceptance
- The classes are active and have no syntax error.
- The hidden tests pass.
- Write your own ABAP Unit tests for the class.