Jeremy Watts said:
class returnWrapper{
private BigDecimal[][][] Pmatrix;
private BigDecimal[][][] Lmatrix;
private BigDecimal[][][] Umatrix;
private Boolean LDMexists;
}
But still am a bit confused as to what comes next
I need to define
the sizes of the P,L & U matrices, and also the initial state of the
boolean, which is true in this case. So do I do these initialisations
within the class? And if so how are these done?
You write a special method called a constructor. A Constructor must have
the same name as the class it's defined in. I'll modify the code above as
is; if you choose to use my suggestions for a complex number class and
such, you can probably figure out the changes you need to make from the
following example; if not, feel free to post again.
class returnWrapper {
private BigDecimal[][][] Pmatrix;
private BigDecimal[][][] Lmatrix;
private BigDecimal[][][] Umatrix;
private Boolean LDMexists;
public returnWrapper() {
this.Pmatrix = new BigDecimal[3][3][3];
this.Lmatrix = new BigDecimal[3][3][3];
this.Umatrix = new BigDecimal[3][3][3];
this.LDMexists = true;
}
}
you would then actually "create" an instance of this class using the "new"
keyword:
returnWrapper anActualInstanceOfTheReturnWrapperClass = new
returnWrapper();
Bit confused as to 'getters' and 'setters', still a java newbie I'm
afraid. So once the arrays and boolean have been declared within the
class wrapper, how are they then referred to outside of it?
when you declare fields (fields are variables inside of objects) as being
private, that means only methods declared within the same class can access
them. 'getters' and 'setters' are just a name for methods whose only
purpose is to get the value inside of fields. You could add getters and
setters like this:
class returnWrapper {
private BigDecimal[][][] Pmatrix;
// etc. for the other matrices
private Boolean LDMexists;
public BigDecimal[][][] getPMatrix() {
return this.PMatrix;
}
public void setPMatrix(BigDecimal[][][] newValue) {
this.PMatrix = newValue;
}
public Boolean getLDMexists() {
return this.LDMexists;
}
public void setLDMexists(Boolean newValue) {
this.LDMExists = newValue;
}
}
or you might want to do it like this:
class returnWrapper {
private BigDecimal[][][] Pmatrix;
// etc. for the other matrices
private Boolean LDMexists;
public BigDecimal[][][] getPMatrix() {
return this.PMatrix;
}
public void setPMatrix(BigDecimal newValue, int x, int y, int z) {
this.PMatrix[x][y][z] = newValue;
}
public Boolean getLDMexists() {
return this.LDMexists;
}
public void setLDMexists() {
this.LDMExists = true;
}
}
- Oliver