import codedraw.CodeDraw; public class NamedBody implements Massive { private final String name; private final Body body; /** * Initializes this with name, mass, current position and movement. */ public NamedBody(String name, double mass, Vector3 massCenter, Vector3 currentMovement) { this(name, new Body(mass, massCenter, currentMovement)); } public NamedBody(String name, Body body) { this.name = name; this.body = body; } public NamedBody(NamedBody other) { this(other.name, new Body(other.body)); } /** * Returns the name of the body. */ public String getName() { return name; } public Body getBody() { return body; } public Vector3 getMassCenter() { return body.getMassCenter(); } public double getMass() { return body.getMass(); } /** * Compares `this` with the specified object. Returns `true` if the specified `o` is not * `null` and is of type `NamedBody` and both `this` and `o` have equal names. * Otherwise, `false` is returned. */ @Override public boolean equals(Object o) { if (!(o instanceof NamedBody b)) return false; return this.name.equals(b.name); } /** * Returns the hashCode of `this`. */ @Override public int hashCode() { return this.name.hashCode(); } /** * Returns a readable representation including the name of this body. */ @Override public String toString() { return this.getName(); } @Override public void move(Vector3 force) { body.move(force); } @Override public void draw(CodeDraw cd) { body.draw(cd); } }