Browse Source

correct some typos, and finishing up to get verion 1 of the Matrix Calculator ready to merge

featureMatrixCalculator
Lukas Reichwein 5 years ago
parent
commit
8339da416d
  1. 30
      src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java
  2. 18
      src/main/java/com/ugsbo/matrixcalc/MatrixCalcIOUtils.java

30
src/main/java/com/ugsbo/matrixcalc/MatrixCalcController.java

@ -9,17 +9,13 @@ import java.util.ArrayList;
public class MatrixCalcController { public class MatrixCalcController {
/**
*
*/
private static final String MULTIPLICATION_STRING = "multiplication"; private static final String MULTIPLICATION_STRING = "multiplication";
private static final String ADDITION_STRING = "addition"; private static final String ADDITION_STRING = "addition";
private static final String SUBSTRACTION_STRING = "substract"; private static final String SUBSTRACTION_STRING = "substract";
private static final String TRANPOSE_STRING = "transpose"; private static final String TRANPOSE_STRING = "transpose";
private static final String CALCDETERMINAT_STRING = "calcDeterminate"; private static final String CALCDETERMINAT_STRING = "calcDeterminate";
// Hier werden die fx:id Attribute verknuepft.
// The fx:id Attributes will be bind here.
@FXML @FXML
private Button multiplyButton, addButton, DetAButton, DetBButton, substractButton, transposeButton; private Button multiplyButton, addButton, DetAButton, DetBButton, substractButton, transposeButton;
@FXML @FXML
@ -60,6 +56,9 @@ public class MatrixCalcController {
invokeOperation(matricies, MULTIPLICATION_STRING); invokeOperation(matricies, MULTIPLICATION_STRING);
}); });
/**
* Convert a String to a matrix, transpose it and output the result.
*/
transposeButton.setOnMouseClicked((event) -> { transposeButton.setOnMouseClicked((event) -> {
String stringMatrixA = matrixATextArea.getText(); String stringMatrixA = matrixATextArea.getText();
String[] stringMatrix = { stringMatrixA, "" }; String[] stringMatrix = { stringMatrixA, "" };
@ -72,6 +71,9 @@ public class MatrixCalcController {
invokeOperation(matricies, TRANPOSE_STRING); invokeOperation(matricies, TRANPOSE_STRING);
}); });
/**
* Convert Strings to matricies, add them and output the result.
*/
addButton.setOnMouseClicked((event) -> { addButton.setOnMouseClicked((event) -> {
String stringMatrixA = matrixATextArea.getText(); String stringMatrixA = matrixATextArea.getText();
String stringMatrixB = matrixBTextArea.getText(); String stringMatrixB = matrixBTextArea.getText();
@ -86,6 +88,9 @@ public class MatrixCalcController {
invokeOperation(matricies, ADDITION_STRING); invokeOperation(matricies, ADDITION_STRING);
}); });
/**
* Convert Strings to matricies, substract them and output the result.
*/
substractButton.setOnMouseClicked((event) -> { substractButton.setOnMouseClicked((event) -> {
String stringMatrixA = matrixATextArea.getText(); String stringMatrixA = matrixATextArea.getText();
String stringMatrixB = matrixBTextArea.getText(); String stringMatrixB = matrixBTextArea.getText();
@ -100,6 +105,9 @@ public class MatrixCalcController {
invokeOperation(matricies, SUBSTRACTION_STRING); invokeOperation(matricies, SUBSTRACTION_STRING);
}); });
/**
* Convert the String of the left inputField to a matrix, calculate the Determinate and output it.
*/
DetAButton.setOnMouseClicked((event) -> { DetAButton.setOnMouseClicked((event) -> {
String stringMatrixA = matrixATextArea.getText(); String stringMatrixA = matrixATextArea.getText();
String[] stringMatrix = { stringMatrixA, "" }; String[] stringMatrix = { stringMatrixA, "" };
@ -112,6 +120,9 @@ public class MatrixCalcController {
invokeOperation(matricies, CALCDETERMINAT_STRING); invokeOperation(matricies, CALCDETERMINAT_STRING);
}); });
/**
* Convert the String of the right inputField to a matrix, calculate the Determinate and output it.
*/
DetBButton.setOnMouseClicked((event) -> { DetBButton.setOnMouseClicked((event) -> {
String stringMatrixB = matrixBTextArea.getText(); String stringMatrixB = matrixBTextArea.getText();
String[] stringMatrix = { "", stringMatrixB }; 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<double[][]> matricies, String operation) { private void invokeOperation(ArrayList<double[][]> matricies, String operation) {
if (matricies.size() == 2) { if (matricies.size() == 2) {
@ -208,9 +219,8 @@ 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 * @param stringMatrix Contains both input matrices if
* numberOfMarriciesToMatch is 2. If the number * numberOfMarriciesToMatch is 2. If the number

18
src/main/java/com/ugsbo/matrixcalc/MatrixCalcIOUtils.java

@ -6,7 +6,7 @@ import java.util.regex.Pattern;
public class MatrixCalcIOUtils { 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 * @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 * @return The Displayable String
*/ */
protected String convertsArrayToStringInOrderToDisplayIt(double[][] array2D) { protected String convertsArrayToStringInOrderToDisplayIt(double[][] array2D) {
@ -28,7 +28,6 @@ public class MatrixCalcIOUtils {
for (int i = 0; i < array2D.length; i++) { for (int i = 0; i < array2D.length; i++) {
for (int j = 0; j < array2D[0].length; j++) { for (int j = 0; j < array2D[0].length; j++) {
displayableString += array2D[i][j] + " "; displayableString += array2D[i][j] + " ";
// System.out.println(result[i][j]);
} }
displayableString += "\n\n"; 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. * matched by the regular Expression.
* *
* @param matrix It is the InputMatrix * @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 { protected void checkInput(String matrix) throws IllegalArgumentException {
if (matrix.length() == 0) { if (matrix.length() == 0) {
@ -54,7 +53,7 @@ public class MatrixCalcIOUtils {
String row2 = "(\\n){0,3}(\\d*\\u0020*){0,3}"; String row2 = "(\\n){0,3}(\\d*\\u0020*){0,3}";
String row3 = "(\\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); Pattern p = Pattern.compile(row1 + row2 + row3);
Matcher m = p.matcher(matrix); Matcher m = p.matcher(matrix);
@ -78,14 +77,13 @@ public class MatrixCalcIOUtils {
String[] singleNumbers = null; String[] singleNumbers = null;
String[] rows = stringMatrix.split("\n"); String[] rows = stringMatrix.split("\n");
for (int i = 0; i < rows.length; i++) { for (int i = 0; i < rows.length; i++) {
// System.out.println(rows[i]);
// Splitting rows into their Numbers // Splitting rows into their Numbers
singleNumbers = rows[i].split("\\s"); singleNumbers = rows[i].split("\\s");
singleNumbersArr.add(singleNumbers); 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]; double[][] matrix = new double[columCount][rowlength];
for (int columIndex = 0; columIndex < columCount; columIndex++) { for (int columIndex = 0; columIndex < columCount; columIndex++) {

Loading…
Cancel
Save