MODULE 4 · CONDITIONS · 8/8

Challenge: motor insurance rating

35 min60 XPExercise

Insurance is one of the biggest employers of COBOL programmers, and at the heart of every policy system is a rating engine: the program that decides whether to offer cover and at what price.

In this challenge you'll write a small one for motor insurance. It does what real rating programs do, in the same order:

  1. Validate the input. Every field is checked and every problem is reported with an error code, so the data-entry team can fix them all in one go rather than one per rerun.
  2. Underwrite. Some applications aren't priced at all: they're referred to a human underwriter, or declined outright.
  3. Rate. Look up a base premium, apply factors, and round the result to the cent.

The input arrives as text, exactly as it would from a screen or an upstream file, so you'll need class conditions before you trust any of it. Use level-88 names for the codes, EVALUATE for the rating tables, and compound conditions where the rules combine.

Before you submit

  • Test each validation on its own and all four failing together — every error line must appear, in code order.
  • Check the boundaries: ages 17, 24, 25, 29, 30, 64 and 65 each sit on the edge of a band.
  • A 19-year-old with four claims wanting group C is both a referral and a decline. The spec says which rule wins; make sure your code agrees.
  • The rated premium is rounded once, at the end.

On the job

Error codes like E01 aren't decoration. Downstream jobs, operations dashboards and support staff key off them, so their meaning is fixed in the spec and must never change. When you add a new validation, you add a new code — you don't reuse an old one.

Your task

Read four lines of text:

Line Field Picture
1 policy number WS-POLICY-NO PIC X(8)
2 driver age WS-AGE-IN PIC X(2)
3 vehicle group WS-GROUP PIC X
4 claims in the last 5 years WS-CLAIMS-IN PIC X

Always start by displaying POLICY: and the policy number.

1. Validate — check every rule and display each failing one:

Code Line to display Rule
E01 E01 INVALID POLICY NUMBER policy number must be all digits
E02 E02 INVALID AGE age must be all digits and at least 17
E03 E03 INVALID VEHICLE GROUP group must be A, B or C
E04 E04 INVALID CLAIMS COUNT claims must be a digit

If any failed, finish with STATUS: REJECTED.

2. Underwrite (valid input only, in this order):

  • 3 or more claims → R01 REFER: 3 OR MORE CLAIMS, then STATUS: REFERRED
  • under 25 and group C → D01 GROUP C NOT OFFERED UNDER 25, then STATUS: DECLINED

3. Rate everything else: premium = base × age factor × claims factor, rounded to the cent.

Group Base Age Factor Claims Factor
A 400.00 17–24 1.80 0 0.90
B 550.00 25–29 1.25 1 1.00
C 800.00 30–64 1.00 2 1.25
65+ 1.15

Display the premium through WS-PREMIUM-OUT, then STATUS: ACCEPTED:

POLICY: 10002345
PREMIUM:   891.00
STATUS: ACCEPTED

(age 22, group B, 0 claims). Once a field has passed its NUMERIC check you can MOVE it into the numeric work field declared for it.

fixed format
Run your program to see its output here. The first visible test's input and datasets are used.
Submit to grade your program against every test.