Help ples
package com.codegym.task.task24.task2405;
/*
Black box
*/
public class Solution implements Action {
public static int actionObjectCount;
private int param;
private Action solutionAction = new Action() {
//write your code here
SecondClass secondClass;
@Override
public void someAction() {
//write your code here
for (int i = param; i >=1; i--){
System.out.println(i);
}
if (param > 0) {//if param >0 call a method of the firstclass subclass
FirstClass firstClass = new FirstClass() {
@Override
public Action getDependentAction() {
return this;
}
};
firstClass.someAction();
secondClass = new SecondClass();
secondClass.someAction();
System.out.println(SecondClass.SPECIFIC_ACTION_FOR_ANONYMOUS_SECOND_CLASS_PARAM + 0);
}
if (param < 0){
secondClass = new SecondClass();
secondClass.someAction();
System.out.println(SecondClass.SPECIFIC_ACTION_FOR_ANONYMOUS_SECOND_CLASS_PARAM + param);
}
//if param < 0 call a method of the second subclass
//here the someAction method of parent class Action must be called super.someAction())
//a FirstClass object must be created here
//a second class object must be created here
}
};
public Solution(int param) {
this.param = param;
}
@Override
public void someAction() {
solutionAction.someAction();
}
/**
* 5
* 4
* 3
* 2
* 1
* FirstClass class, someAction method
* SecondClass class, someAction method
* Specific action for anonymous SecondClass, param = 0
* The number of created Action objects is 2
* SecondClass class, someAction method
* Specific action for anonymous SecondClass, param = -1
* The number of created Action objects is 3
*/
public static void main(String[] args) {
Solution solution = new Solution(5);
solution.someAction();
System.out.println("The number of created Action objects is " + actionObjectCount);
solution = new Solution(-1);
solution.someAction();
System.out.println("The number of created Action objects is " + actionObjectCount);
}
}