diff --git a/src/Acceleration.java b/src/Acceleration.java index 3bccc68..c60c686 100644 --- a/src/Acceleration.java +++ b/src/Acceleration.java @@ -1,25 +1,41 @@ import java.util.*; public class Acceleration { - private double mass; - private Map.Entry force; - private Velocity velocity; - private Onground onground; - private Map.Entry acceleration; - public void updateMass(double mass) { - this.mass = mass; - acceleration = (this.onground.getOnground() ? new AbstractMap.SimpleEntry<>((force.getKey()/mass), 0.0) : new AbstractMap.SimpleEntry<>((force.getKey()/mass), (force.getValue()/mass))); - velocity.updateAcceleration(acceleration); - } - public void updateForce(Map.Entry force) { - this.force = force; - acceleration = (this.onground.getOnground() ? new AbstractMap.SimpleEntry<>((force.getKey()/mass), 0.0) : new AbstractMap.SimpleEntry<>((force.getKey()/mass), (force.getValue()/mass))); - velocity.updateAcceleration(acceleration); - } - public Acceleration(Velocity velocity, Onground onground) { - this.onground = onground; - } - public Map.Entry getAcceleration() { - return acceleration; - } + private double massValue; + private Map.Entry forceValue; + private Velocity velocity; + private Onground onground; + private Map.Entry value; + + public void updateByMass(double mass) { + this.massValue = mass; + Map.Entry temp_l0; + if (this.onground.getOnground()) { + temp_l0 = new AbstractMap.SimpleEntry<>((forceValue.getKey() / mass), 0.0); + } else { + temp_l0 = new AbstractMap.SimpleEntry<>((forceValue.getKey() / mass), (forceValue.getValue() / mass)); + } + value = temp_l0; + velocity.updateByAcceleration(value); + } + + public void updateByForce(Map.Entry force) { + this.forceValue = force; + Map.Entry temp_l1; + if (this.onground.getOnground()) { + temp_l1 = new AbstractMap.SimpleEntry<>((force.getKey() / massValue), 0.0); + } else { + temp_l1 = new AbstractMap.SimpleEntry<>((force.getKey() / massValue), (force.getValue() / massValue)); + } + value = temp_l1; + velocity.updateByAcceleration(value); + } + + public Acceleration(Velocity velocity, Onground onground) { + this.onground = onground; + } + + public Map.Entry getValue() { + return value; + } } \ No newline at end of file