Files
abap-llm/tasks_gen/train/G1308/spec.md

3.4 KiB

Hello, we need a check for hot-air balloon flights before launch. The flight office calls this check for each planned flight. The check must stop a flight when a limit is exceeded. The caller needs one exception for each reason.

The exception class {{P}}CX_BALLOON_FLIGHT already exists in package $TMP. It is active. It inherits from CX_STATIC_CHECK. It has a public read-only attribute MV_TEXT of type string and a constructor with importing parameter IV_TEXT of type string. The constructor writes IV_TEXT to MV_TEXT. The flight office knows four figures: 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.

Please create the class {{P}}BALLOON_CHECKER in package $TMP. The class is public and final. It can be created without constructor parameters. It 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, and raising {{P}}CX_BALLOON_FLIGHT. Do not add other public methods.

Also create these exception classes in package $TMP. Each class inherits from {{P}}CX_BALLOON_FLIGHT. {{P}}CX_BALLOON_CREW has a constructor with importing IV_PASSENGERS type i and IV_LIMIT type i. {{P}}CX_BALLOON_WEIGHT has a constructor with importing IV_WEIGHT_KG type i and IV_LIMIT_KG type i. {{P}}CX_BALLOON_WIND has a constructor with importing IV_WIND_KMH type i and IV_LIMIT_KMH type i. {{P}}CX_BALLOON_CLOUD has a constructor with importing IV_CLOUD_BASE_M type i and IV_LIMIT_M type i. Each constructor writes the message text to MV_TEXT. The rules below give the text of each exception.

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. First, check the 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 ". For example, 12 passengers give the text "Passengers 12 exceeds the limit 8". Second, check the 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". For example, 700 kilograms give the text "Weight 700 kg exceeds the limit 640 kg". Third, check the 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". For example, 25 kilometres per hour give the text "Wind 25 km/h exceeds the limit 18 km/h". Fourth, check the 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". For example, 200 metres give the text "Cloud base 200 m is below the limit 300 m". Finally, if no rule fails, the free payload is 640 minus IV_WEIGHT_KG. Return the free payload in RV_FREE_KG.

The release target is ABAP Platform 2025 (SAP_BASIS 816). Follow Clean ABAP. Keep the method length below 40 statements. Do not use global variables. Do not write comments that restate the code. Do not change {{P}}CX_BALLOON_FLIGHT.

The classes must be active and have no syntax error. The hidden tests must pass. Write your own ABAP Unit tests for the class.