Vector
package com.gmail.vhrushyn;
public class Vector {
private double x;
private double y;
private double z;
public Vector(double x, double y, double z) {
super();
this.x = x;
this.y = y;
this.z = z;
}
public Vector() {
super();
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public double getZ() {
return z;
}
public void setZ(double z) {
this.z = z;
}
@Override
public String toString() {
return "Vector [x=" + x + ", y=" + y + ", z=" + z + "]";
}
public Vector summVector(Vector b) {
Vector c = new Vector(this.x + b.x, this.y + b.y, this.z + b.z);
return c;
}
public double scalMultVector(Vector b) {
double c = this.x * b.x + this.y * b.y + this.z * b.z;
return c;
}
public Vector vectMultVector(Vector b) {
Vector c = new Vector(this.y * b.z - this.z * b.y, this.z * b.x - this.x * b.z,
this.x * b.y - this.y * b.x);
return c;
}
}
package com.gmail.vhrushyn;
public class Main {
public static void main(String[] args) {
Vector a = new Vector(5, 7, 2);
Vector b = new Vector(2, 5, 8);
System.out.println("summ of 'a' "+a+" and 'b' "+b+" is 'c' "+a.summVector(b));
System.out.println("scalar multiplication of 'a' "+a+" and 'b' "+b+" is "+a.scalMultVector(b));
System.out.println("vector multiplication of 'a' "+a+" and 'b' "+b+" is 'c' "+a.vectMultVector(b));
}
}