small changes

This commit is contained in:
2018-02-27 10:47:06 +01:00
parent ada39c72b6
commit 83ae8d18fb
2 changed files with 15 additions and 6 deletions

View File

@@ -13,7 +13,6 @@ public class Worm {
private double minRadius;
// mass
private double mass;
private final int rho = 1062;
// points
private int points;
@@ -104,6 +103,9 @@ public class Worm {
}
public void setRadius(double radius) {
if (radius < this.minRadius) {
throw new IllegalArgumentException();
}
this.radius = radius;
setMass(radius);
}
@@ -122,7 +124,8 @@ public class Worm {
private void setMass(double radius) {
double mass = this.rho * (4 / 3 * Math.PI * Math.pow(radius, 3));
final int rho = 1062;
double mass = rho * (4 / 3 * Math.PI * Math.pow(radius, 3));
this.mass = mass;
setMaxPoints(mass);
@@ -133,6 +136,11 @@ public class Worm {
}
public void setPoints(int points) {
if (points > this.maxPoints) {
points = this.maxPoints;
}
else if (points < 0)
points = 0;
this.points = points;
}
@@ -141,5 +149,6 @@ public class Worm {
}
private void setMaxPoints(double maxPoints) {
this.maxPoints = (int) Math.round(maxPoints);
setPoints(this.points);
}
}