Question: Convert the following C++ code to equivalent Java. Change the arrays/vectors to ArrayList's. (Ignore the fact that 0.0 is an inappropriate default value you can

Convert the following C++ code to equivalent Java. Change the arrays/vectors to ArrayList's. (Ignore the fact that 0.0 is an inappropriate default value you can look up 's NAN and isnan() and Java's Float.NaN if you want a better option.)

class Q1

{

private: float * vals;

int numVals;

static const float EPS = .00001;

Generator gen;

public: Q1(int _numVals, float val1, Generator & _gen) : numVals(_numVals), gen(_gen)

{ vals = new float[numVals];

vals[0] = val1;

for (int i = 1; i < numVals; i++) vals[i] = 0.0f; }

float getNth(int n)

{ if (n < 0 || n >= numVals) throw "index out of bounds";

if (-EPS < vals[n] && vals[n] < EPS) vals[n] = gen.calc(getNth(n-1)); return vals[n]; }

};

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!