2.4 KiB
2.4 KiB
1. Goal
Evaluate soil samples from farms. A laboratory program calls the evaluation before it gives a fertilizer recommendation. The program needs the average pH, the average nutrient value, and a grade for each delivery of samples.
2. Open questions
None.
3. Context
- The class {{P}}SOIL_EVALUATOR is new. It is in package $TMP.
- The laboratory program collects the samples of one delivery in a table.
- Each sample has a pH value and a nutrient value.
4. Contract
- Create the class {{P}}SOIL_EVALUATOR in package $TMP.
- The class is public, final, and has a public constructor without parameters.
- Define these public types:
- TY_PH: type P, length 3, decimals 1.
- TY_NUTRIENT: type I.
- TY_STATUS: type C, length 1.
- TY_GRADE: type C, length 1.
- TY_SAMPLE: a structure with PH (type TY_PH) and NUTRIENT (type TY_NUTRIENT).
- TT_SAMPLE: a standard table of TY_SAMPLE with empty key.
- TY_RESULT: a structure with STATUS (type TY_STATUS), AVG_PH (type TY_PH), AVG_NUTRIENT (type TY_NUTRIENT), and GRADE (type TY_GRADE).
- Define these public constants:
- C_STATUS_OK TYPE TY_STATUS VALUE 'O'.
- C_STATUS_ERROR TYPE TY_STATUS VALUE 'E'.
- C_GRADE_A TYPE TY_GRADE VALUE 'A'.
- C_GRADE_B TYPE TY_GRADE VALUE 'B'.
- C_GRADE_C TYPE TY_GRADE VALUE 'C'.
- Define this public method:
- EVALUATE IMPORTING it_samples TYPE tt_sample RETURNING VALUE(rs_result) TYPE ty_result.
- Do not add other public methods.
5. Business rules
Apply the rules in this sequence.
- If any sample has a pH less than 0 or greater than 14, set STATUS = C_STATUS_ERROR. Leave the other fields of the result initial. Return the result.
- Calculate the average pH and the average nutrient of all samples. Round the average pH to one decimal place. Round the average nutrient to the nearest integer.
- Determine the grade:
- If the average pH is between 6.0 and 7.5 inclusive and the average nutrient is 50 or more, set GRADE = C_GRADE_A.
- Else if the average pH is between 5.0 and 8.0 inclusive and the average nutrient is 30 or more, set GRADE = C_GRADE_B.
- Else set GRADE = C_GRADE_C.
- Set STATUS = C_STATUS_OK.
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 other objects.
7. Acceptance
- The class is active and has no syntax error.
- Write your own ABAP Unit tests for the class.