Max and Min

Report a typo

Use the strategy pattern to implement algorithms to find max and min values in a given array. The basic structure of the provided classes is described below: your job is to complete it.

The class Finder represents the general finding algorithm itself. It has find(int[] numbers) method that returns the result of finding according to the specified strategy.

The interface FindingStrategy provides getResult() method to write new concrete finding strategies.

Please, do not change the interface FindingStrategy, and do not rename the existing methods.

If the array is empty, the Finder should return Integer.MAX_VALUE in case of finding the min value and Integer.MIN_VALUE in case of finding the max value.

Tests 1-5 check MinFindingStrategy, tests 6-10 check MaxFindingStrategy. Do not forget to check your solution when the passed array has the size 0 or 1.
Write a program in Java 17
import java.util.Scanner;

class Finder {

private FindingStrategy strategy;

public Finder(FindingStrategy strategy) {
// write your code here
}

/**
* It performs the search algorithm according to the given strategy
*/
public int find(int[] numbers) {
// write your code here
}
}

interface FindingStrategy {

/**
* Returns search result
*/
int getResult(int[] numbers);

}

class MaxFindingStrategy implements FindingStrategy {

public int getResult(int[] numbers) {
// write your code here
}
}

class MinFindingStrategy implements FindingStrategy {

___

Create a free account to access the full topic