Skip to content

Instantly share code, notes, and snippets.

@mariiaKolokolova
Created June 4, 2020 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariiaKolokolova/e15562628d4f98816f5da1b319308054 to your computer and use it in GitHub Desktop.
Save mariiaKolokolova/e15562628d4f98816f5da1b319308054 to your computer and use it in GitHub Desktop.
OOP_HomeWork1c
package maricka.kolokolova;
public class Mian {
public static void main(String[] args) {
// TODO Auto-generated method stub
Vector3D vctOne = new Vector3D(1, 2, 3);
Vector3D vctTwo = new Vector3D(5.1, 6.2, 7.3);
Vector3D vctThree = new Vector3D(8, 9.2, 12);
System.out.println("Sum of vectors: " + vctOne.sum(vctOne, vctTwo));
System.out.println("Scalar multiplication of vectors: " + vctOne.scalMult(vctOne, vctThree));
System.out.println("Vectorial multiplication of vectors: " + vctOne.vectMult(vctOne, vctThree));
}
}
package maricka.kolokolova;
public class Vector3D {
private double x;
private double y;
private double z;
public Vector3D(double x, double y, double z) {
super();
this.x = x;
this.y = y;
this.z = z;
}
public Vector3D() {
super();
// TODO Auto-generated constructor stub
}
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;
}
public Vector3D sum(Vector3D vct1, Vector3D vct2) {
double rezX = vct1.x + vct2.x;
double rezY = vct1.y + vct2.y;
double rezZ = vct1.z + vct2.z;
Vector3D vctR = new Vector3D(rezX, rezY, rezZ);
return vctR;
}
public double scalMult(Vector3D vct1, Vector3D vct2) {
double rez = vct1.x * vct2.x + vct1.y * vct2.y + vct1.z * vct2.z;
return rez;
}
public Vector3D vectMult(Vector3D vct1, Vector3D vct2) {
double rezX = vct1.y * vct2.z - vct1.z * vct2.y;
double rezY = vct1.z * vct2.x - vct1.x * vct2.z;
double rezZ = vct1.x * vct2.y - vct1.y * vct2.x;
Vector3D vctR = new Vector3D(rezX, rezY, rezZ);
return vctR;
}
@Override
public String toString() {
return "Vector3D [x=" + x + ", y=" + y + ", z=" + z + "]";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment