diff options
| author | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-11-30 22:15:59 +0100 |
|---|---|---|
| committer | Stefan Suhren <suhren.stefan@fh-swf.de> | 2015-11-30 22:15:59 +0100 |
| commit | 36d5ea556d610740a117612e4548510c155ad22e (patch) | |
| tree | 80257df01a318273589c0a7e4ffd942dc325d863 | |
| parent | 24117a58257553e5446b8658a4eaf783b1357708 (diff) | |
| download | Notepad---36d5ea556d610740a117612e4548510c155ad22e.tar.gz Notepad---36d5ea556d610740a117612e4548510c155ad22e.zip | |
Extract calculations and extend scale
| -rw-r--r-- | src/de/fhswf/in/inf/se/notepadMinusMinus/view/MainView.fxml | 2 | ||||
| -rw-r--r-- | src/de/fhswf/in/inf/se/notepadMinusMinus/view/MainViewController.java | 53 |
2 files changed, 32 insertions, 23 deletions
diff --git a/src/de/fhswf/in/inf/se/notepadMinusMinus/view/MainView.fxml b/src/de/fhswf/in/inf/se/notepadMinusMinus/view/MainView.fxml index 2cb5647..6f9f92c 100644 --- a/src/de/fhswf/in/inf/se/notepadMinusMinus/view/MainView.fxml +++ b/src/de/fhswf/in/inf/se/notepadMinusMinus/view/MainView.fxml @@ -82,7 +82,7 @@ <Label text="ECTS:" /> <Label fx:id="ectsSumLabel" text="0" GridPane.columnIndex="1" /> <Label text="Note:" GridPane.columnIndex="2" /> - <Label fx:id="averageGradeLabel" text="0,0" GridPane.columnIndex="3" /> + <Label fx:id="averageGradeLabel" text="0,00" GridPane.columnIndex="3" /> <Button mnemonicParsing="false" onAction="#handleNewValue" text="Neu" GridPane.columnIndex="4" /> <Button fx:id="deleteButton" disable="true" mnemonicParsing="false" onAction="#handleDeleteValue" text="Löschen" GridPane.columnIndex="5" /> <Label text="Bachelor Arbeit" GridPane.rowIndex="1" /> diff --git a/src/de/fhswf/in/inf/se/notepadMinusMinus/view/MainViewController.java b/src/de/fhswf/in/inf/se/notepadMinusMinus/view/MainViewController.java index b4a37d7..0e870a5 100644 --- a/src/de/fhswf/in/inf/se/notepadMinusMinus/view/MainViewController.java +++ b/src/de/fhswf/in/inf/se/notepadMinusMinus/view/MainViewController.java @@ -139,28 +139,8 @@ public class MainViewController colloquiumComboBox.valueProperty() .bindBidirectional(main.getGradesObject().thesisProperty()); - gradeTable.getItems().addListener((Change<? extends Grade> change) -> { - ectsSumLabel.setText("0"); - averageGradeLabel.setText("0.0"); - int sumEcts = 0; - BigDecimal gradesSumWeighted = BigDecimal.ZERO; - for (Grade grade : gradeTable.getItems()) - { - if (grade.getGrade().compareTo(BigDecimal.ZERO) != 0) - { - sumEcts += grade.getEcts(); - gradesSumWeighted = gradesSumWeighted.add(grade.getGrade() - .multiply(new BigDecimal(grade.getEcts()))); - } - } - if (sumEcts > 0) - { - ectsSumLabel.setText(String.valueOf(sumEcts)); - averageGradeLabel.setText(gradesSumWeighted - .divide(new BigDecimal(sumEcts), 2, RoundingMode.HALF_UP) - .toString()); - } - }); + gradeTable.getItems().addListener(( + Change<? extends Grade> change) -> calculateEctsAndAverageGrade()); } /** @@ -308,4 +288,33 @@ public class MainViewController { Platform.exit(); } + + /** + * TODO Add method comment here + * + * @param main + */ + private void calculateEctsAndAverageGrade() + { + ectsSumLabel.setText("0"); + averageGradeLabel.setText("0.00"); + int sumEcts = 0; + BigDecimal gradesSumWeighted = BigDecimal.ZERO; + for (Grade grade : gradeTable.getItems()) + { + if (grade.getGrade().compareTo(BigDecimal.ZERO) != 0) + { + sumEcts += grade.getEcts(); + gradesSumWeighted = gradesSumWeighted.add( + grade.getGrade().multiply(new BigDecimal(grade.getEcts()))); + } + } + if (sumEcts > 0) + { + ectsSumLabel.setText(String.valueOf(sumEcts)); + averageGradeLabel.setText(gradesSumWeighted + .divide(new BigDecimal(sumEcts), 2, RoundingMode.HALF_UP) + .toString()); + } + } } |
