2.9 KiB
2.9 KiB
1. Goal
A data centre operator bills its customers for the server racks that they rent. A billing program calls one class for each billing run. The class returns one row per customer with the number of racks and the monthly fee.
2. Open questions
None.
3. Context
- There are no seed objects. Create the class in package $TMP.
- A rack has a rack ID, a customer, a size class and a power class.
- The billing input can contain the same rack more than once.
- The class is the only object of this task.
4. Contract
Create the class {{P}}RACK_BILLING in package $TMP.
- The class is public and final. It has a public constructor without parameters.
- Public types: TYPES ty_size TYPE c LENGTH 1. TYPES ty_power TYPE c LENGTH 1. TYPES ty_customer TYPE c LENGTH 10. TYPES ty_fee TYPE p LENGTH 8 DECIMALS 2. TYPES: BEGIN OF ty_rack, rack_id TYPE c LENGTH 10, customer TYPE ty_customer, size_class TYPE ty_size, power_class TYPE ty_power, END OF ty_rack. TYPES tt_racks TYPE STANDARD TABLE OF ty_rack WITH EMPTY KEY. TYPES: BEGIN OF ty_bill, customer TYPE ty_customer, rack_count TYPE i, total_fee TYPE ty_fee, END OF ty_bill. TYPES tt_bills TYPE STANDARD TABLE OF ty_bill WITH EMPTY KEY.
- Public method: METHODS calculate IMPORTING it_racks TYPE tt_racks RETURNING VALUE(rt_bills) TYPE tt_bills.
- Do not add other public methods.
5. Business rules
A rack is valid when its size class is S, M or L and its power class is A, B or C.
- Read it_racks in the given order.
- A rack ID identifies one rack. If a rack ID was already read, skip the rack. Remember the rack ID of every rack that you read, also when the rack is not valid.
- If the size class is not S, M or L, or the power class is not A, B or C, skip the rack.
- The monthly fee of a valid rack is the base fee of its size class plus the
surcharge of its power class:
- base fee: S = 50.00, M = 120.00, L = 250.00
- power surcharge: A = 0.00, B = 30.00, C = 70.00
- Add the fee of the rack to the total fee of its customer. Increase the rack count of the customer by 1.
- After all racks, apply a volume discount to the total fee of each customer:
- 20 or more racks: 20 percent
- 10 or more racks: 10 percent
- less than 10 racks: no discount
- The result has one row for each customer with at least one valid rack. The row contains the customer, the number of valid racks and the total fee after the discount.
- Sort the result by customer in ascending order.
- If it_racks is empty, return an empty table.
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: no other object.
7. Acceptance
- The class is active and has no syntax error.
- The hidden tests pass.
- Write your own ABAP Unit tests for the class.