I have this exercise that I need to refactor using Template design pattern. I have seen a basic explanation of how it works, but I can't get a clear idea of how I should implement my solution. Could anyone help me out? What would be the logic in this case?
I have this BodyFatCalculator class:
package bodyfat;
public class BodyFatCalculator {
public double calculate( BodyMeassures body, boolean isWoman ) {
double fatPercent = 0;
if( isWoman ) {
fatPercent = Math.log( body.getWaist() + body.getHip() ) - body.getWeight()
* Math.log( body.getHeight() );
}
else {
fatPercent = Math.log( body.getWaist() + body.getAbdomen() ) - body.getWeight() * Math.
log( body.getHeight() );
}
return fatPercent;
}
}
And I also have this BodyMeassures class:
package bodyfat;
public class BodyMeasures {
private double height;
private double waist;
private double weight;
private double hip;
private double abdomen;
public BodyMeasures( double height, double waist, double weight, double hip, double abdomen ) {
this.height = height;
this.waist = waist;
this.weight = weight;
this.hip = hip;
this.abdomen = abdomen;
}
/**
* @return the height
*/
public double getHeight() {
return height;
}
/**
* @return the waist
*/
public double getWaist() {
return waist;
}
/**
* @return the weight
*/
public double getWeight() {
return weight;
}
/**
* @return the hip
*/
public double getHip() {
return hip;
}
/**
* @return the abdomen
*/
public double getAbdomen() {
return abdomen;
}
}
Aucun commentaire:
Enregistrer un commentaire