diff --git a/nbproject/project.properties b/nbproject/project.properties index f704bcf..4905bab 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,73 +1,73 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -application.title=TSE -application.vendor=aNNiMON -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/TSE.jar -dist.javadoc.dir=${dist.dir}/javadoc -endorsed.classpath= -excludes= -includes=** -jar.compress=false -javac.classpath= -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.processorpath=\ - ${javac.classpath} -javac.source=1.7 -javac.target=1.7 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -main.class=tse.Main -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test +annotation.processing.enabled=true +annotation.processing.enabled.in.editor=false +annotation.processing.processors.list= +annotation.processing.run.all.processors=true +annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output +application.title=TSE +application.vendor=aNNiMON +build.classes.dir=${build.dir}/classes +build.classes.excludes=**/*.java,**/*.form +# This directory is removed when the project is cleaned: +build.dir=build +build.generated.dir=${build.dir}/generated +build.generated.sources.dir=${build.dir}/generated-sources +# Only compile against the classpath explicitly listed here: +build.sysclasspath=ignore +build.test.classes.dir=${build.dir}/test/classes +build.test.results.dir=${build.dir}/test/results +# Uncomment to specify the preferred debugger connection transport: +#debug.transport=dt_socket +debug.classpath=\ + ${run.classpath} +debug.test.classpath=\ + ${run.test.classpath} +# This directory is removed when the project is cleaned: +dist.dir=dist +dist.jar=${dist.dir}/TSE.jar +dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= +excludes= +includes=** +jar.compress=false +javac.classpath= +# Space-separated list of extra javac options +javac.compilerargs= +javac.deprecation=false +javac.processorpath=\ + ${javac.classpath} +javac.source=1.7 +javac.target=1.7 +javac.test.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +javac.test.processorpath=\ + ${javac.test.classpath} +javadoc.additionalparam= +javadoc.author=false +javadoc.encoding=${source.encoding} +javadoc.noindex=false +javadoc.nonavbar=false +javadoc.notree=false +javadoc.private=false +javadoc.splitindex=true +javadoc.use=true +javadoc.version=false +javadoc.windowtitle= +main.class=module1.variant4.Task_2 +manifest.file=manifest.mf +meta.inf.dir=${src.dir}/META-INF +mkdist.disabled=false +platform.active=default_platform +run.classpath=\ + ${javac.classpath}:\ + ${build.classes.dir} +# Space-separated list of JVM arguments used when running the project. +# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. +# To set system properties for unit tests define test-sys-prop.name=value: +run.jvmargs= +run.test.classpath=\ + ${javac.test.classpath}:\ + ${build.test.classes.dir} +source.encoding=UTF-8 +src.dir=src +test.src.dir=test diff --git a/src/module1/variant4/Matrix.java b/src/module1/variant4/Matrix.java new file mode 100644 index 0000000..251034e --- /dev/null +++ b/src/module1/variant4/Matrix.java @@ -0,0 +1,98 @@ +package module1.variant4; + +/** + * + * @author aNNiMON + */ +public class Matrix { + + protected int[][] matrix; + + public Matrix(int row, int columns) { + if ( (row < 1) || (columns < 1) ) { + throw new RuntimeException("Размер матрицы должен быть больше 0"); + } + matrix = new int[row][columns]; + } + + public Matrix(int[][] matrix) { + this.matrix = matrix; + } + + public int getRowSize() { + return matrix.length; + } + + public int getColumnSize() { + return matrix[0].length; + } + + public int[][] getMatrix() { + return matrix; + } + + public void setMatrix(int[][] matrix) { + this.matrix = matrix; + } + + public void setRow(int row, int[] vector) { + this.matrix[row] = vector; + } + + public void setCell(int row, int column, int value) { + this.matrix[row][column] = value; + } + + public Matrix multiply(Matrix other) { + int[][] matrixA = matrix; + int[][] matrixB = other.matrix; + + int rowsA = matrixA.length; + int columnsA = matrixA[0].length; + int columnsB = matrixB.length; + if (columnsB != columnsA) { + throw new RuntimeException("Размеры матриц не совпадают"); + } + + int[][] matrixC = new int[rowsA][columnsB]; + for (int i = 0; i < rowsA; i++) { + for (int j = 0; j < columnsB; j++) { + for (int k = 0; k < columnsA; k++) { + matrixC[i][j] += matrixA[i][k] * matrixB[k][j]; + } + } + } + + return new Matrix(matrixC); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Матрица\n"); + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < matrix[0].length; j++) { + sb.append(matrix[i][j]).append(' '); + } + sb.append("\n"); + } + return sb.toString(); + } + + @Override + protected Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + @Override + public boolean equals(Object obj) { + return super.equals(obj); + } + + @Override + public int hashCode() { + return super.hashCode(); + } + + +} diff --git a/src/module1/variant4/Task_2.java b/src/module1/variant4/Task_2.java new file mode 100644 index 0000000..f5538c8 --- /dev/null +++ b/src/module1/variant4/Task_2.java @@ -0,0 +1,47 @@ +package module1.variant4; + +import java.util.ArrayList; +import java.util.Random; + +/** + * + * @author aNNiMON + */ +public class Task_2 { + + public static void main(String[] args) { + Random rnd = new Random(); + + Matrix mt1 = new Matrix(1, 3); + for (int i = 0; i < mt1.getColumnSize(); i++) { + mt1.setCell(0, i, rnd.nextInt(10)); + } + + Matrix mt2 = new Matrix(3, 3); + for (int i = 0; i < mt2.getRowSize(); i++) { + for (int j = 0; j < mt2.getColumnSize(); j++) { + mt2.setCell(i, j, rnd.nextInt(10)); + } + } + + Vector vector = new Vector(3); + for (int i = 0; i < vector.getVectorSize(); i++) { + vector.setCell(i, rnd.nextInt(10)); + } + + + ArrayList list = new ArrayList<>(); + list.add(mt1); + list.add(mt2); + list.add(vector); + + for (Matrix matrix : list) { + System.out.println(matrix.toString()); + } + System.out.println("AxB= " + mt1.multiply(mt2).toString()); + System.out.println("V*A= " + vector.getMultiplyMatrixAndVector(mt1).toString()); + System.out.println("V*B= " + vector.getMultiplyMatrixAndVector(mt2).toString()); + System.out.println("V*V= " + vector.getVectorScalarMultiply(vector)); + } + +} diff --git a/src/module1/variant4/Vector.java b/src/module1/variant4/Vector.java new file mode 100644 index 0000000..300c168 --- /dev/null +++ b/src/module1/variant4/Vector.java @@ -0,0 +1,73 @@ +package module1.variant4; + +/** + * + * @author aNNiMON + */ +public class Vector extends Matrix { + + public Vector(int size) { + super(new int[1][size]); + } + + public Vector(int[] vector) { + super(new int[][] { + vector + }); + } + + public int[] getVector() { + return matrix[0]; + } + + public int getVectorSize() { + return matrix[0].length; + } + + public void setCell(int column, int value) { + super.setCell(0, column, value); + } + + public Vector getMultiplyMatrixAndVector(Matrix matrix) { + int[][] matrixA = matrix.getMatrix(); + int rowsA = matrixA.length; + int columnsA = matrixA[0].length; + + int[] vector = getVector(); + + if (vector.length != columnsA) { + throw new RuntimeException("Размер матрицы и длина вектора не совпадают"); + } + int[] result = new int[rowsA]; + for (int i = 0; i < rowsA; i++) { + for (int j = 0; j < columnsA; j++) { + result[i] += (matrixA[i][j] * vector[j]); + } + } + return new Vector(result); + } + + public int getVectorScalarMultiply(Vector other) { + int[] vectorA = getVector(); + int[] vectorB = other.getVector(); + + int result = 0; + for (int i = 0; i < vectorA.length; i++) { + result += vectorA[i] * vectorB[i]; + } + + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("Вектор\n"); + for (int j = 0; j < matrix[0].length; j++) { + sb.append(matrix[0][j]).append(' '); + } + sb.append("\n"); + return sb.toString(); + } + +}