
public class NamedBody extends Body {

    private final String name;

    /**
     * Initializes this with name, mass, current position and movement.
     */
    public NamedBody(String name, double mass, Vector3 massCenter, Vector3 currentMovement) {
        super(mass, massCenter, currentMovement);
        this.name = name;
    }

    public NamedBody(String name, double mass) {
        super(mass);
        this.name = name;
    }

    public NamedBody(String name) {
        super();
        this.name = name;
    }

    public NamedBody(String name, Body body) {
        super(body);
        this.name = name;
    }

    public NamedBody(NamedBody other) {
        super(other);
        this.name = other.name;
    }

    /**
     * Returns the name of the body.
     */
    public String getName() {
        return this.name;
    }

    /**
     * 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();
    }
}
