Files

99 lines
4.8 KiB
Markdown

# 1. Goal
A vending machine operator plans the refill of its vending machines. A planning
program collects the machines and the refill quantities. The program then asks
the planner for the machines with a low fill level, for the largest refills, and
for the totals per district. The program needs one class for this work.
# 2. Open questions
None.
# 3. Context
- Package $TMP is the development package.
- Only the class is in scope. The planning program is not in scope.
- A machine has a machine ID, a district, and a fill level in percent.
- A refill is a quantity of items for one machine.
- The class holds the machines of one planning run in memory.
- One program calls the class many times during a planning run.
# 4. Contract
Create the class {{P}}REFILL_PLANNER in package $TMP.
The class is public and final. It has a public constructor without parameters.
Do not add other public methods.
The public section of the class contains these types:
- ty_machine_id TYPE c LENGTH 8
- ty_district TYPE c LENGTH 4
- ty_quantity TYPE i
- ty_fill_level TYPE i
- ty_machine with the components machine_id TYPE ty_machine_id,
district TYPE ty_district, and fill_level TYPE ty_fill_level
- tt_machines with the line type ty_machine
- ty_refill with the components machine_id TYPE ty_machine_id and
quantity TYPE ty_quantity
- tt_refills with the line type ty_refill
- ty_district_summary with the components district TYPE ty_district,
machines TYPE i, and quantity TYPE ty_quantity
- tt_district_summary with the line type ty_district_summary
The class has these public methods:
- add_machine with the importing parameters iv_machine_id TYPE ty_machine_id,
iv_district TYPE ty_district, and iv_fill_level TYPE ty_fill_level.
- add_refill with the importing parameters iv_machine_id TYPE ty_machine_id and
iv_quantity TYPE ty_quantity and with the returning parameter rv_accepted TYPE
abap_bool.
- get_refill with the importing parameter iv_machine_id TYPE ty_machine_id and
the returning parameter rv_quantity TYPE ty_quantity.
- machines_below with the importing parameter iv_fill_level TYPE ty_fill_level
and the returning parameter rt_machines TYPE tt_machines.
- top_refills with the importing parameter iv_count TYPE i and the returning
parameter rt_refills TYPE tt_refills.
- district_summary with the returning parameter rt_summary TYPE
tt_district_summary.
- total_quantity with the returning parameter rv_total TYPE ty_quantity.
# 5. Business rules
1. A new instance of the class holds no machine.
2. The key of a machine is the machine ID. Two machines with the same machine ID
are one machine.
3. Convert every machine ID and every district to upper case before the class
stores it or compares it.
4. add_machine: If the machine ID is not known, add the machine with the given
district and the given fill level. If the machine ID is known, replace the
district and the fill level of the machine. The refill quantity of the
machine does not change.
5. add_refill: If iv_quantity is zero or less, return abap_false and change
nothing.
6. add_refill: If the machine ID is not known, return abap_false and change
nothing.
7. add_refill: Else add iv_quantity to the refill quantity of the machine and
return abap_true.
8. get_refill: Return the refill quantity of the machine. Return 0 if the
machine has no refill quantity or if the machine ID is not known.
9. machines_below: Return all machines with a fill level that is less than
iv_fill_level. Sort the result by fill level in ascending order. Sort
machines with the same fill level by machine ID in ascending order.
10. top_refills: Return the machines that have a refill quantity greater than
zero. The result has at most iv_count entries. Sort the result by refill
quantity in descending order. Sort machines with the same refill quantity
by machine ID in ascending order. If iv_count is zero or less, return an
empty table. If fewer machines have a refill quantity, return all of them.
11. district_summary: Return one row for each district that has at least one
machine. machines is the number of machines in the district. quantity is
the sum of the refill quantities of the machines in the district. Sort the
result by district in ascending order.
12. total_quantity: Return the sum of the refill quantities of all machines.
# 6. Constraints
- Release target: SAP_BASIS 816 (ABAP Platform 2025).
- Coding standards: Clean ABAP. Keep every method below 40 statements. Use no
global variable. Add no comment that restates the code. Pass large parameters
by reference.
- Out of scope: database tables, CDS views, reports, function modules, and
screen programming.
# 7. Acceptance
- The class is active and has no syntax error.
- The hidden tests pass.
- Write your own ABAP Unit tests for the class.
- The class has no ATC finding of priority 1 or priority 2.