Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package calculator.datatypes.vector;
- import calculator.AbstractValue;
- import calculator.DivisionByZeroException;
- import calculator.OperationNotSupportedException;
- public class VectorValue extends AbstractValue {
- private int x;
- private int y;
- private int z;
- public VectorValue(int x, int y, int z) {
- super();
- this.x = x;
- this.y = y;
- this.z = z;
- }
- @Override
- public AbstractValue add(AbstractValue operand) throws OperationNotSupportedException {
- int x = this.x + ((VectorValue) operand).x;
- int y = this.y + ((VectorValue) operand).y;
- int z = this.z + ((VectorValue) operand).z;
- return new VectorValue(x, y, z);
- }
- @Override
- public AbstractValue sub(AbstractValue operand) throws OperationNotSupportedException {
- int x = this.x - ((VectorValue) operand).x;
- int y = this.y - ((VectorValue) operand).y;
- int z = this.z - ((VectorValue) operand).z;
- return new VectorValue(x, y, z);
- }
- @Override
- public AbstractValue mul(AbstractValue operand) throws OperationNotSupportedException {
- int i = this.y * ((VectorValue) operand).z - this.z * ((VectorValue) operand).y;
- int j = -(this.x * ((VectorValue) operand).z - this.z * ((VectorValue) operand).x);
- int k = this.x * ((VectorValue) operand).y - this.y * ((VectorValue) operand).x;
- return new VectorValue(i, j, k);
- }
- @Override
- public AbstractValue div(AbstractValue operand) throws DivisionByZeroException, OperationNotSupportedException {
- throw new OperationNotSupportedException("div");
- }
- @Override
- public String toString() {
- StringBuilder builder = new StringBuilder("Vector3D(");
- builder.append(this.x + ", ");
- builder.append(this.y + ", ");
- builder.append(this.z + ")");
- return builder.toString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement