From 8088bfece9b21184b464bd705de3c9e9c1d04c23 Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Mon, 26 Feb 2018 17:57:37 +0100 Subject: [PATCH] some changes to worm --- src/Worm.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Worm.java b/src/Worm.java index 4b668c8..ee98bed 100644 --- a/src/Worm.java +++ b/src/Worm.java @@ -13,9 +13,11 @@ public class Worm { private double minRadius; // mass private double mass; + private final int rho = 1062; // points - private double points; + private int points; + private int maxPoints; // name private final String name; @@ -103,6 +105,7 @@ public class Worm { public void setRadius(double radius) { this.radius = radius; + setMass(radius); } public double getMinRadius() { @@ -117,19 +120,26 @@ public class Worm { return this.mass; } - public void setMass(double mass) { + private void setMass(double radius) { + + double mass = this.rho * (4 / 3 * Math.PI * Math.pow(radius, 3)); + this.mass = mass; + setMaxPoints(mass); } - public double getPoints() { + public int getPoints() { return this.points; } - public void setPoints(double points) { + public void setPoints(int points) { this.points = points; } public String getName() { return this.name; } + private void setMaxPoints(double maxPoints) { + this.maxPoints = (int) Math.round(maxPoints); + } }