JAVA
Given an integer n the Collatz successors of n are defined to be: B(n) = {n is even n/2 Otherwise n * 3 + 1 The trajectory of n, is defined to be the list of successors of n (n is the starting point or SP). Reaching 1 as a successoris considered "success." The Collatz Tree (forward chaining). Consider the following relation: Given an integer n > 4 the Collatz successors of n are defined to be: F(n) = {n is even AND ((n - 1) mod 3 = 0) {2 times n, (n - 1)/3} Otherwise {2 times n} Consider the following forward chaining procedure: Given the integer n (goal) and a collection of integers that initially includes only the integer 8. Following a collection management policy (e.g., FIFO), Do: a. Remove an integer (say j) from the collection b. Insert the successor[s] of j to the collection. c. Stop with "success" if n is in the collection Assignment Instructions: Your assignment is to write an interactive Java program that: Obtains the desired chaining mode via a widget (from the user) Obtains the number n via a widget Obtains a limit (l) on the number of iterations of successors generation via a widget Implements the appropriate chaining method: using a sorted list and removing the least element from the list for the forward chaining a. Implement the Comparable and/or Comparator interface(s) in order to sort the list (do NOT write your own sort function, do not use Maps!) At each iteration the backward chaining module prints the trajectory followed so far into a new line in a csv file and the forward chaining module prints the current contents of the collection to a csv file. The program terminates after l iterations of successor generation and reports the status (success or failure) of the run under the l- constraint - via a widget