A general calculation with memory for java