You will implement a data processing pipeline using the Strategy Pattern. The pipeline will:
- Clean the input data using a chosen cleaning strategy,
- Analyze the cleaned data using one of five analysis strategies,
- Output the result to either the console or a text file.
Your job is to implement one method that ties these strategies together.
public double process(
CleaningType cleaningType,
AnalysisType analysisType,
OutputType outputType,
List<Integer> data
) throws Exception
-
Parameters:
cleaningType
→ which cleaning strategy to useanalysisType
→ which analysis to performoutputType
→ where to send the result (console or file)data
→ the list of integers to process
-
Return:
- The numeric result of the chosen analysis as a
double
.
- The numeric result of the chosen analysis as a
-
Order of operations: Clean → Analyze → Output → Return result
- REMOVE_NEGATIVES: drop all values
< 0
- REPLACE_NEGATIVES_WITH_ZERO: replace all values
< 0
with0
-
MEAN
- Arithmetic average of all numbers.
- Empty list →
NaN
.
-
MEDIAN
- Middle value after sorting (even length → average of two middles).
- Empty list →
NaN
.
-
STD_DEV
- Population standard deviation (divide by N, not N−1).
- Empty list →
NaN
.
-
P90_NEAREST_RANK
- Sort ascending;
rank = ceil(0.90 * N)
(1-based); return value at that rank. - Empty list →
NaN
.
- Sort ascending;
-
TOP3_FREQUENT_COUNT_SUM
- Count frequencies of each distinct value.
- Sort by count desc, break ties by value asc.
- Take the top 3 frequencies and sum them (fewer than 3 → sum existing).
- Empty list →
0.0
.
-
CONSOLE: Print
Result = <value>
to standard output. -
TEXT_FILE: Write
Result = <value>
totarget/result.txt
.- Overwrite if file exists.
- Create directories if needed.
- Use the Strategy Pattern and the provided factory; no long
if/else
ladders. - Do not modify the input list directly.
- Handle empty input according to the rules above.
- Write output exactly in the format
Result = <value>
.
CleaningType | AnalysisType | OutputType | Input Data | Result |
---|---|---|---|---|
REMOVE_NEGATIVES | MEAN | CONSOLE | [5, -2, 7, 8] | Mean = 6.666… |
REPLACE_NEGATIVES_WITH_ZERO | MEDIAN | TEXT_FILE | [5, -2, 7, 8] | Median = 6.0 |
REMOVE_NEGATIVES | P90_NEAREST_RANK | CONSOLE | [1,3,5,7,9,11,13,15,17,19] | 17.0 |
REPLACE_NEGATIVES_WITH_ZERO | STD_DEV | TEXT_FILE | [2,4,4,4,5,5,7,9] | StdDev = 2.0 |
REMOVE_NEGATIVES | TOP3_FREQUENT_COUNT_SUM | CONSOLE | [5,5,5,1,1,2,2,3] | Count sum = 7.0 |