Game Development Reference
In-Depth Information
The ODE Class
We'll start with the class that represents the ODE to be solved, which will be called the ODE class.
This class will represent a generic ordinary differential equation. Classes to represent specific
types of ODEs, to model spring or projectile motion for instance, will be written as subclasses
of the ODE class. The ODE class declares three fields that represent the number of first-order
ODEs to be solved, an array containing the dependent variable values, and the value of the
independent variable. The constructor initializes the numEqns variable and sizes the q[] array
that will store the dependent variable values.
public abstract class ODE
{
// Declare fields used by the class
private int numEqns; // number of equations to solve
private double q[]; // array of dependent variables
private double s; // independent variable
// Constructor
public ODE(int numEqns) {
this.numEqns = numEqns;
q = new double[numEqns];
}
The ODE class declares a standard series of get/set methods to return or change the values
of the fields declared in the class.
// These methods return the number of equations or
// the value of the dependent or independent variables.
public int getNumEqns() {
return numEqns;
}
public double getS() {
return s;
}
public double getQ(int index) {
return q[index];
}
public double[] getAllQ() {
return q;
}
Search WWH ::




Custom Search