From b028f8100ab3e58dfd13df713bfd7dcc9aa719c8 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Fri, 3 Feb 2023 01:38:22 +0100 Subject: [PATCH] BMI Wert auf Zwei Nachkommastellen abrunden + Test "BMI" --- src/main/java/src/TasksFrame.java | 6 ++++-- src/test/java/src/TasksFrameTest.java | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index a9c7611..fddb709 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -147,8 +147,10 @@ public class TasksFrame extends JFrame { } public double bmi(double height, double weight) { - - return weight / (height * height); + double result = 0.0; + result = weight / (height * height); + double roundOff = Math.round(result * 100.0) / 100.0; + return roundOff; } diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index ff2a433..26872fc 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -158,6 +158,17 @@ class TasksFrameTest { int c = Integer.parseInt(tasksFrame.umrechnen(48)); assertEquals(110000, c); } + + @Test + void test_bmi(){ + TasksFrame tasksFrame = new TasksFrame(); + double a = tasksFrame.bmi(1.65, 60.0); + assertEquals(22.04, a); + double b = tasksFrame.bmi(1.95, 72); + assertEquals(18.93, b); + double c = tasksFrame.bmi(1.24, 30); + assertEquals(19.51, c); + } }