From 8339da416d517d7cd518061a7975c77eff2119d9 Mon Sep 17 00:00:00 2001 From: Lukas Reichwein Date: Mon, 15 Jul 2019 18:15:36 +0200 Subject: [PATCH] correct some typos, and finishing up to get verion 1 of the Matrix Calculator ready to merge --- .../matrixcalc/MatrixCalcController.java | 32 ++++++++++++------- .../ugsbo/matrixcalc/MatrixCalcIOUtils.java | 20 ++++++------ 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java index 21b470f..f857eb0 100644 --- a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java +++ b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java @@ -9,17 +9,13 @@ import java.util.ArrayList; public class MatrixCalcController { - /** - * - */ - private static final String MULTIPLICATION_STRING = "multiplication"; private static final String ADDITION_STRING = "addition"; private static final String SUBSTRACTION_STRING = "substract"; private static final String TRANPOSE_STRING = "transpose"; private static final String CALCDETERMINAT_STRING = "calcDeterminate"; - // Hier werden die fx:id Attribute verknuepft. + // The fx:id Attributes will be bind here. @FXML private Button multiplyButton, addButton, DetAButton, DetBButton, substractButton, transposeButton; @FXML @@ -60,6 +56,9 @@ public class MatrixCalcController { invokeOperation(matricies, MULTIPLICATION_STRING); }); + /** + * Convert a String to a matrix, transpose it and output the result. + */ transposeButton.setOnMouseClicked((event) -> { String stringMatrixA = matrixATextArea.getText(); String[] stringMatrix = { stringMatrixA, "" }; @@ -72,6 +71,9 @@ public class MatrixCalcController { invokeOperation(matricies, TRANPOSE_STRING); }); + /** + * Convert Strings to matricies, add them and output the result. + */ addButton.setOnMouseClicked((event) -> { String stringMatrixA = matrixATextArea.getText(); String stringMatrixB = matrixBTextArea.getText(); @@ -86,6 +88,9 @@ public class MatrixCalcController { invokeOperation(matricies, ADDITION_STRING); }); + /** + * Convert Strings to matricies, substract them and output the result. + */ substractButton.setOnMouseClicked((event) -> { String stringMatrixA = matrixATextArea.getText(); String stringMatrixB = matrixBTextArea.getText(); @@ -100,6 +105,9 @@ public class MatrixCalcController { invokeOperation(matricies, SUBSTRACTION_STRING); }); + /** + * Convert the String of the left inputField to a matrix, calculate the Determinate and output it. + */ DetAButton.setOnMouseClicked((event) -> { String stringMatrixA = matrixATextArea.getText(); String[] stringMatrix = { stringMatrixA, "" }; @@ -112,6 +120,9 @@ public class MatrixCalcController { invokeOperation(matricies, CALCDETERMINAT_STRING); }); + /** + * Convert the String of the right inputField to a matrix, calculate the Determinate and output it. + */ DetBButton.setOnMouseClicked((event) -> { String stringMatrixB = matrixBTextArea.getText(); String[] stringMatrix = { "", stringMatrixB }; @@ -126,9 +137,9 @@ public class MatrixCalcController { } /** - * Invokes the right operations form the MatrixCalcMath class - * @param matricies contains both or onely one Matrix - * @param operation One of the Global Constats to select wich Operation is needed. + * Invokes the needed operations form the MatrixCalcMath class + * @param matricies Contains both Matricies or onely one Matrix + * @param operation One of the global Constats to select wich Operation is needed. */ private void invokeOperation(ArrayList matricies, String operation) { if (matricies.size() == 2) { @@ -208,15 +219,14 @@ public class MatrixCalcController { } } - // TODO Wirte tests for the extracted Methode. /** - * Checks the Input and Displays it if the Input is Valid. + * Checks the Input and Displays it if the Input is valid. * * @param stringMatrix Contains both input matrices if * numberOfMarriciesToMatch is 2. If the number * is 1 than one of them has to be a empty String * @param numberOfMatricesToMatch If the number is 1 onely one Marix will be - * verifyed and the otherone needs to be an empty + * verifyed and the other one needs to be an empty * String in the stringMatrix */ private void checkInputAndDisplayIfInputIsNotValid(String[] stringMatrix, int numberOfMatricesToMatch) { diff --git a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcIOUtils.java b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcIOUtils.java index 20c5130..e929081 100644 --- a/src/main/java/com/ugsbo/matrixcalc/MatrixCalcIOUtils.java +++ b/src/main/java/com/ugsbo/matrixcalc/MatrixCalcIOUtils.java @@ -6,7 +6,7 @@ import java.util.regex.Pattern; public class MatrixCalcIOUtils { /** - * Prints a given 2D-Array to the output text Field. + * Prints a given 2D-Array to the output Textfield. * * @param output2DArray The Array that gets Displayed */ @@ -18,9 +18,9 @@ public class MatrixCalcIOUtils { } /** - * Converts Array to String in oder to Display it. + * Converts 2D-Array to String in order to Display it. * - * @param array2D the array wich will be converted to an Displayable String + * @param array2D The array wich will be converted to an Displayable String * @return The Displayable String */ protected String convertsArrayToStringInOrderToDisplayIt(double[][] array2D) { @@ -28,7 +28,6 @@ public class MatrixCalcIOUtils { for (int i = 0; i < array2D.length; i++) { for (int j = 0; j < array2D[0].length; j++) { displayableString += array2D[i][j] + " "; - // System.out.println(result[i][j]); } displayableString += "\n\n"; } @@ -36,11 +35,11 @@ public class MatrixCalcIOUtils { } /** - * Chcks if the Input is Valid, with Regex. Returns true if the Matrix can be + * Checks if the Input is Valid, with Regex. Returns true if the Matrix can be * matched by the regular Expression. * * @param matrix It is the InputMatrix - * @return true if the Matrix is valid Input. + * @return True if the Matrix is valid Input. */ protected void checkInput(String matrix) throws IllegalArgumentException { if (matrix.length() == 0) { @@ -50,11 +49,11 @@ public class MatrixCalcIOUtils { // Matches digits witch following spaces 1 to 3 times String row1 = "(\\d*\\u0020*){1,3}"; // Matches newlineCurrierReturn followed by digits witch following spaces 1 to - // 3times + // 3 times String row2 = "(\\n){0,3}(\\d*\\u0020*){0,3}"; String row3 = "(\\n){0,3}(\\d*\\u0020*){0,3}"; - // TODO get the input check more stricktly missing matrix slots are allowed. + // TODO for verion 2 get the input check more stricktly missing matrix slots are allowed. Pattern p = Pattern.compile(row1 + row2 + row3); Matcher m = p.matcher(matrix); @@ -78,14 +77,13 @@ public class MatrixCalcIOUtils { String[] singleNumbers = null; String[] rows = stringMatrix.split("\n"); for (int i = 0; i < rows.length; i++) { - // System.out.println(rows[i]); // Splitting rows into their Numbers singleNumbers = rows[i].split("\\s"); singleNumbersArr.add(singleNumbers); } - int rowlength = singleNumbersArr.get(0).length; // row.length - int columCount = singleNumbersArr.size(); // output.length + int rowlength = singleNumbersArr.get(0).length; + int columCount = singleNumbersArr.size(); double[][] matrix = new double[columCount][rowlength]; for (int columIndex = 0; columIndex < columCount; columIndex++) {