Created
January 19, 2017 08:59
-
-
Save Banafasto/1050605ed60dc5017b70d1eb626bd63f to your computer and use it in GitHub Desktop.
Lessons1Exapmle3OOP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gmail.kudr641.example3; | |
import java.util.Scanner; | |
public class ActionWithTheVector { | |
public Vector3d[] createArrayVectors(){ | |
Scanner scanner = new Scanner(System.in); | |
System.out.print("How many vectors needed?"); | |
int how = scanner.nextInt(); | |
Vector3d[] arrayVector = new Vector3d[how]; | |
for(int i = 0; i < how; i += 1){ | |
System.out.println("Input parameters " + (i + 1) + " vectors"); | |
System.out.print("x = "); | |
int x = scanner.nextInt(); | |
System.out.print("y = "); | |
int y = scanner.nextInt(); | |
System.out.print("z = "); | |
int z = scanner.nextInt(); | |
arrayVector[i] = new Vector3d(x, y, z); | |
} | |
scanner.close(); | |
return arrayVector; | |
} | |
public void printArrayVctor(Vector3d[] arrayVector){ | |
for(int i = 0; i < arrayVector.length; i += 1){ | |
System.out.println(arrayVector[i]); | |
} | |
} | |
public void printSumAllVector(Vector3d[] arrayVector){ | |
for(int i = 0; i < arrayVector.length; i += 1){ | |
for(int j = i + 1; j < arrayVector.length; j += 1){ | |
System.out.println("Sum vector " + (i + 1) + " vector " + (j + 1) + | |
": " + sumVector(arrayVector[i], arrayVector[j])); | |
} | |
} | |
} | |
public void printScalarVector(Vector3d[] arrayVector){ | |
for(int i = 0; i < arrayVector.length; i += 1){ | |
for(int j = i + 1; j < arrayVector.length; j += 1){ | |
System.out.println("Scalar vector " + (i + 1) + " vector " + (j + 1) + | |
": " + scalarVector(arrayVector[i], arrayVector[j])); | |
} | |
} | |
} | |
public void printCompositionVector(Vector3d[] arrayVector){ | |
for(int i = 0; i < arrayVector.length; i += 1){ | |
for(int j = i + 1; j < arrayVector.length; j += 1){ | |
System.out.println("Vector product vector " + (i + 1) + " vector " + (j + 1) + | |
": " + compositionVector(arrayVector[i], arrayVector[j])); | |
} | |
} | |
} | |
private Vector3d sumVector(Vector3d one, Vector3d two){ | |
return new Vector3d(one.getX() + two.getX(), one.getY() + two.getY(), | |
one.getZ() + two.getZ()); | |
} | |
private int scalarVector(Vector3d one, Vector3d two){ | |
return one.getX() * two.getX() + one.getY() * two.getY() + one.getZ() * two.getZ(); | |
} | |
private Vector3d compositionVector(Vector3d one, Vector3d two){ | |
return new Vector3d(one.getY() * two.getZ() - two.getY() * one.getZ(), | |
one.getX() * two.getZ() - two.getX() * one.getZ(), | |
one.getX() * two.getY()- two.getY() * one.getY()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gmail.kudr641.example3; | |
public class Runner { | |
public static void main(String[] args) { | |
ActionWithTheVector awtv = new ActionWithTheVector(); | |
Vector3d[] arrayVector = awtv.createArrayVectors(); | |
awtv.printArrayVctor(arrayVector); | |
awtv.printSumAllVector(arrayVector); | |
awtv.printCompositionVector(arrayVector); | |
awtv.printScalarVector(arrayVector); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gmail.kudr641.example3; | |
public class Vector3d { | |
private int x; | |
private int y; | |
private int z; | |
public Vector3d(int x, int y, int z){ | |
this.x = x; | |
this.y = y; | |
this.z = z; | |
} | |
@Override | |
public String toString() { | |
return "Vector3d [x=" + x + ", y=" + y + ", z=" + z + "]"; | |
} | |
public int getX() { | |
return x; | |
} | |
public int getY() { | |
return y; | |
} | |
public int getZ() { | |
return z; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment