Dynamic Solution for the Optimal Control Program in Java