Interface for processing numbers: Filtering and Transformation

Java Medium interfaces

Task «Interface for processing numbers: Filtering and Transformation»

Implement the NumberFilter and NumberTransformer interfaces with a single method boolean filter(int number) and int transform(int number) respectively. Create the classes EvenFilter (keeps even numbers), OddFilter (keeps odd numbers), SquareTransformer (returns the square of a number), IncrementTransformer (increments by 1). In main, read an integer n, then n integers. Apply a filter and a transformation to each number: if the filter returns true, output the result of the transformation, otherwise output the number itself. Use polymorphism through interfaces.

Input Format

First line: an integer n (1 ≤ n ≤ 100). Second line: n integers separated by spaces, each from -1000 to 1000.

Output Format

Output n numbers (separated by spaces) — the result of processing each number according to the rule: if the number is even, output its square; if odd, output the number increased by 1.

Examples

Example 1

INPUT
3 -2 -1 0
OUTPUT
4 0 0

Example 2

INPUT
5 1 2 3 4 5
OUTPUT
2 4 4 16 6
main.java