Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014aUaQeLnwbb1zTpN7kHeat
58 lines
2.4 KiB
Markdown
58 lines
2.4 KiB
Markdown
# 1. Goal
|
|
A water utility bills its customers for the water that they use. The billing
|
|
program needs one service that calculates the consumption of each water meter
|
|
from the readings of a period.
|
|
|
|
# 2. Open questions
|
|
None.
|
|
|
|
# 3. Context
|
|
- The interface {{P}}IF_METER_READING exists in package $TMP. It is active.
|
|
- The interface contains these public types:
|
|
TY_METER_ID (CHAR 10), TY_READING_DATE (date), TY_VALUE (integer),
|
|
TY_READING (METER_ID, READING_DATE, READING_VALUE),
|
|
TT_READINGS (a table of TY_READING),
|
|
TY_RESULT (METER_ID, OPENING_VALUE, CLOSING_VALUE, CONSUMPTION),
|
|
TT_RESULT (a table of TY_RESULT).
|
|
- The interface has one method:
|
|
CALCULATE IMPORTING it_readings TYPE tt_readings
|
|
RETURNING VALUE(rt_result) TYPE tt_result.
|
|
- A reading is the meter value in cubic metres that a reader wrote down on a
|
|
date.
|
|
|
|
# 4. Contract
|
|
- Create the class {{P}}METER_CONSUMPTION in package $TMP.
|
|
- The class is public, final, and has a public constructor without parameters.
|
|
- The class implements {{P}}IF_METER_READING.
|
|
- Do not add other public methods.
|
|
|
|
# 5. Business rules
|
|
The method gets the readings of all meters of one period. The input table can be
|
|
unsorted. It can contain more than one reading for the same meter and the same
|
|
date.
|
|
1. Ignore every reading whose value is less than zero.
|
|
2. If two or more readings have the same meter ID and the same date, only the
|
|
reading with the highest value counts. Ignore the other readings of that
|
|
date.
|
|
3. For each meter, the opening value is the value of the earliest date of the
|
|
meter, and the closing value is the value of the latest date of the meter.
|
|
If a meter has only one reading, the opening value and the closing value are
|
|
the value of that reading.
|
|
4. The consumption of a meter is the closing value minus the opening value. If
|
|
that difference is less than zero, the consumption is zero.
|
|
5. The result has one row for each meter with at least one reading that rule 1
|
|
does not ignore.
|
|
6. The result is sorted by meter ID in ascending order.
|
|
7. If no reading remains after rule 1, the result is empty.
|
|
|
|
# 6. Constraints
|
|
- Release target: 8.16.
|
|
- 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}}IF_METER_READING.
|
|
|
|
# 7. Acceptance
|
|
- The class is active and has no syntax error.
|
|
- The hidden tests pass.
|
|
- Write your own ABAP Unit tests for the class.
|