Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
64 lines
2.2 KiB
Markdown
64 lines
2.2 KiB
Markdown
# 1. Goal
|
|
Calculate the annual premium of a car insurance policy. An insurance program calls the calculation before it sends an offer to a customer. The program needs one premium for each policy.
|
|
|
|
# 2. Open questions
|
|
None.
|
|
|
|
# 3. Context
|
|
- Package $TMP.
|
|
- No other objects are required.
|
|
|
|
# 4. Contract
|
|
- Create the class {{P}}INSURANCE_PREMIUM in package $TMP.
|
|
- The class is public, final, and has a public constructor without parameters.
|
|
- The class has the public type TY_REGION (CHAR 2) and TY_PREMIUM (P LENGTH 8 DECIMALS 2).
|
|
- The class has one public method:
|
|
CALCULATE_PREMIUM
|
|
IMPORTING
|
|
iv_age TYPE i
|
|
iv_power_kw TYPE i
|
|
iv_region TYPE ty_region
|
|
iv_claim_free_years TYPE i
|
|
RETURNING
|
|
VALUE(rv_premium) TYPE ty_premium.
|
|
- Do not add other public methods.
|
|
|
|
# 5. Business rules
|
|
Apply the rules in this sequence.
|
|
1. Validate the inputs:
|
|
- iv_age must be between 18 and 99.
|
|
- iv_power_kw must be greater than 0.
|
|
- iv_claim_free_years must not be negative.
|
|
- iv_region must be one of the known regions (see rule 2).
|
|
If any check fails, return 0.
|
|
2. The base premium depends on the region:
|
|
A1: 150, B2: 200, C3: 250, D4: 300, E5: 350.
|
|
3. The age factor:
|
|
- age < 25: 1.5
|
|
- 25 <= age <= 65: 1.0
|
|
- age > 65: 1.2
|
|
4. The power factor:
|
|
- power <= 50 kW: 0.9
|
|
- 51 <= power <= 100 kW: 1.0
|
|
- 101 <= power <= 150 kW: 1.3
|
|
- power > 150 kW: 1.6
|
|
5. The claim-free discount:
|
|
- Each claim-free year gives a 5% discount.
|
|
- The maximum discount is 30%.
|
|
- The discount factor is 1 minus the discount (e.g., 0 claim-free years: 1.0, 6 or more: 0.7).
|
|
6. Calculate the premium:
|
|
premium = base premium * age factor * power factor * discount factor.
|
|
Calculate with full precision and round the final result to 2 decimals.
|
|
7. If the rounded premium is less than 100, return 100.
|
|
8. Else return the rounded premium.
|
|
|
|
# 6. Constraints
|
|
- Release target: 7.58.
|
|
- Coding standards: Clean ABAP. Method length below 40 statements. No global variables. No comment that restates the code. One statement per line.
|
|
- Out of scope: do not create other objects.
|
|
|
|
# 7. Acceptance
|
|
- The class is active and has no syntax error.
|
|
- The hidden tests pass.
|
|
- Write your own ABAP Unit tests for the class.
|