Finished AB5
This commit is contained in:
@@ -1,46 +1,79 @@
|
||||
public class NamedBody /* TODO: add clause(s) */ {
|
||||
import codedraw.CodeDraw;
|
||||
|
||||
// TODO: add missing parts of this class.
|
||||
public class NamedBody implements Massive {
|
||||
|
||||
private final String name;
|
||||
private final Body body;
|
||||
|
||||
/**
|
||||
* Initializes this with name, mass, current position and movement. The associated force
|
||||
* is initialized with a zero vector.
|
||||
* Initializes this with name, mass, current position and movement.
|
||||
*/
|
||||
public NamedBody(String name, double mass, Vector3 massCenter, Vector3 currentMovement) {
|
||||
// TODO: implement constructor.
|
||||
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() {
|
||||
// TODO: implement method.
|
||||
return "";
|
||||
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.
|
||||
* Otherwise, `false` is returned.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
//TODO: implement method.
|
||||
return false;
|
||||
if (!(o instanceof NamedBody b)) return false;
|
||||
return this.name.equals(b.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hashCode of `this`.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
//TODO: implement method.
|
||||
return 0;
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a readable representation including the name of this body.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
//TODO: implement method.
|
||||
return "";
|
||||
return this.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move(Vector3 force) {
|
||||
body.move(force);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(CodeDraw cd) {
|
||||
body.draw(cd);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user