Я пишу программу для моделирования температуры тела человека при физической нагрузке. Я написал широкий класс «купе», который выглядит следующим образом:
public class compartment {
public float height;
public float weight;
public float age;
public float mrest;
public float HR;
public float VO2;
public float [] temps;
public float [] K = {54.29f, 41.76f, 15.87f, 41.76f, 20.88f};
private float BF;
private float T;
private float H;
private float hCap;
private float dnsty;
public compartment(float height, float weight, float age, float HR, float VO2, float [] temps) {
height = this.height;
weight = this.weight;
age = this.age;
mrest = 1.5f * weight;
HR = this.HR;
VO2 = this.VO2;
temps = this.temps;
}
// GETTERS
public float getBF() {
return BF;
}
public float getT() {
return T;
}
public float getH() {
return H;
}
public float gethCap() {
return hCap;
}
public float getDnsty() {
return dnsty;
}
// SETTERS
public void setBF(float BF) {
BF = this.BF;
}
public void setT(float T) {
T = this.T;
}
public void setH(float H) {
H = this.H;
}
public void sethCap(float hCap) {
hCap = this.hCap;
}
public void setDnsty(float dnsty) {
dnsty = this.dnsty;
}
}
Затем я написал подкласс, который является основным отделением корпуса, который выглядит следующим образом:
public class core extends compartment{
public void calc() {
// Setting up constants
int n = 0;
float H = 0.824f;
setDnsty(1.1f);
sethCap(51);
// Calculating blood flow
float pctMaxHr = HR/(220-age);
float dubois = (float) (2.0247 * Math.pow(height, 0.725) * Math.pow(weight, 0.425));
float pctMaxBf = (float) ((pctMaxHr <= 39) ? 100:100 - 1.086*(pctMaxHr-39));
float maxBf = (float) (0.92*dubois*3.2);
float bf = (pctMaxBf)*(maxBf);
// Calculating heat production
setH(mrest*H);
// Calculating derivative
float Q = getH() - (K[n]*(temps[n] - temps[n+1])) - (bf*getDnsty()*gethCap()*(temps[n] - temps[5]));
// Adjusting the temperature
float T = temps[n] + Q;
setT(T);
}
public core(float height, float weight, float age, float HR, float VO2, float[] temps) {
super(height, weight, age, HR, VO2, temps);
calc();
}
}
Однако, когда я пытаюсь создать объект 'core', я получаю java NullPointerException
Exception in thread "main" java.lang.NullPointerException
at core.calc(core.java:22)
at core.<init>(core.java:32)
at model.main(model.java:7)
Строка 22 - это строка
float Q = getH() - (K[n]*(temps[n] - temps[n+1])) - (bf*getDnsty()*gethCap()*(temps[n] - temps[5]));
Выполнение некоторой отладки с помощью System .out.println кажется, что ни одна из переменных не создается должным образом, например, когда я печатаю переменную mrest или height, они обе получаются как 0.0
Я пропустил фундаментальное свойство наследования? Что я делаю неправильно? Спасибо.