Re: Feat. Req: Automatically measure all walls
Code: Select all
public void execute() {
float volumeInCm3 = 0;
double wallLength = 0;
double totalWallLength = 0;
StringBuffer wallDimensionsMsg = new StringBuffer();
for (Wall wall : getHome().getWalls()){
if (wall.getXStart() == wall.getXEnd()) {
wallLength = wall.getYStart() - wall.getYEnd();
} else if (wall.getYStart() == wall.getYEnd()){
wallLength = wall.getXStart() - wall.getXEnd();
} else {
wallLength = Math.sqrt(Math.pow((wall.getXEnd()-wall.getXStart()),2)
+ (Math.pow((wall.getYEnd() - wall.getYStart()),2)));
}
// get rid of negative values
wallLength = ((wallLength < 0 ? -wallLength : wallLength));
totalWallLength+=wallLength;
wallDimensionsMsg.append("Wall: length " + wallLength + "\n");
wallDimensionsMsg.append(String.format(" Total wall length = %.2f cm", totalWallLength));
JOptionPane.showMessageDialog(null, wallDimensionsMsg);
}