Files

2.7 KiB

1. Goal

The class {{P}}MOVE_PRICER calculates the price of a house move for a moving company. Users report three defects in the calculation. Fix the class. All other behavior stays the same.

2. Open questions

None.

3. Context

  • The class {{P}}MOVE_PRICER exists in package $TMP. It is active.
  • The class is public and final. It has a public constructor without parameters.
  • The public section contains the type TY_PRICE and the constants C_BASE_FEE, C_VOLUME_FEE, C_DISTANCE_FEE, C_FLOOR_FEE, C_PACKING_FEE and C_WEEKEND_RATE.
  • The class has one public method: CALCULATE IMPORTING iv_distance_km TYPE i iv_volume_m3 TYPE i iv_floor TYPE i iv_packing TYPE abap_bool iv_weekend TYPE abap_bool RETURNING VALUE(rv_price) TYPE ty_price.
  • CALCULATE gives the price of one move. The price has these parts: a base fee, a volume fee, a distance fee, a floor surcharge, a packing fee and a weekend surcharge.

4. Contract

  • Fix the class {{P}}MOVE_PRICER in package $TMP.
  • Keep the public interface. The type TY_PRICE, the constants and the signature of CALCULATE stay the same.
  • Do not add public methods. Do not rename the class.

5. Business rules

The price has these parts:

  1. Base fee: 250.00 EUR for each move.
  2. Volume fee: 40.00 EUR for each cubic metre of the move (iv_volume_m3).
  3. Distance fee: 1.20 EUR for each kilometre of the distance (iv_distance_km).
  4. Floor surcharge: 15.00 EUR for each floor above the ground floor. iv_floor is the floor number. Floor 0 is the ground floor. If iv_floor is 0 or less, the surcharge is 0.00 EUR.
  5. Packing fee: 180.00 EUR if iv_packing is abap_true. Else 0.00 EUR.
  6. Subtotal: the sum of the parts 1 to 5.
  7. Weekend surcharge: if iv_weekend is abap_true, add 12 % of the subtotal, rounded to 2 decimal places. Else add 0.00 EUR.
  8. The price is the subtotal plus the weekend surcharge. The input values are not negative.

Users report these defects:

  • A move over 15 km is charged a distance fee for only 10 km. Every kilometre must be charged.
  • A move to the first floor is free. The first floor must cost 15.00 EUR. A move to the third floor costs 30.00 EUR. It must cost 45.00 EUR.
  • A weekend move is always charged a weekend surcharge of 30.00 EUR. The surcharge must be 12 % of the subtotal.

6. Constraints

  • Release target: SAP_BASIS 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 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.