From c638ef735531b79bd4b55a7eaff38a6b01cc4eec Mon Sep 17 00:00:00 2001 From: MSeibert97 Date: Tue, 16 Jul 2019 15:41:53 +0200 Subject: [PATCH] =?UTF-8?q?Commit=20#11.=20Erste=20Berechnungsfunktionen?= =?UTF-8?q?=20f=C3=BCr=20das=20Gesammtergebnis=20erstellt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/workspace.xml | 56 +++++++++++++++++++-------- src/FitnessTest_M.java | 87 ++++++++++++++++++++++++++---------------- 2 files changed, 94 insertions(+), 49 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index bcf2dbc..1ec3d73 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -32,14 +32,18 @@ - - + + - - - - + + + + + + + + @@ -48,7 +52,7 @@ - + @@ -491,7 +495,21 @@ - + @@ -711,14 +731,18 @@ - - + + - - - - + + + + + + + + diff --git a/src/FitnessTest_M.java b/src/FitnessTest_M.java index 68a7158..8367ebd 100644 --- a/src/FitnessTest_M.java +++ b/src/FitnessTest_M.java @@ -32,8 +32,13 @@ public class FitnessTest_M extends JFrame { JButton question2_confirm = null; JButton question3_confirm = null; JButton question4_confirm = null; + JButton totalscore_submit = null; - int points = 0; + int points1; + int points2; + int points3; + int points4; + int points5; public FitnessTest_M() { @@ -126,13 +131,13 @@ public class FitnessTest_M extends JFrame { public void actionPerformed(ActionEvent e) { if (e.getSource() == question1_confirm) { if(question_tf1.getText().startsWith("A") || question_tf1.getText().startsWith("a")) { - points += 10; + points1 = 10; } if(question_tf1.getText().startsWith("B") || question_tf1.getText().startsWith("b")) { - points += 5; + points1 = 5; } if(question_tf1.getText().startsWith("C") || question_tf1.getText().startsWith("c")) { - points += 0; + points1 = 0; } } } @@ -144,13 +149,13 @@ public class FitnessTest_M extends JFrame { public void actionPerformed(ActionEvent e) { if (e.getSource() == question2_confirm) { if(question_tf2.getText().startsWith("A") || question_tf2.getText().startsWith("a")) { - points += 10; + points2 = 10; } if(question_tf2.getText().startsWith("B") || question_tf2.getText().startsWith("b")) { - points += 5; + points2 = 5; } if(question_tf2.getText().startsWith("C") || question_tf2.getText().startsWith("c")) { - points += 0; + points2 = 0; } } } @@ -162,13 +167,13 @@ public class FitnessTest_M extends JFrame { public void actionPerformed(ActionEvent e) { if (e.getSource() == question3_confirm) { if(question_tf3.getText().startsWith("A") || question_tf3.getText().startsWith("a")) { - points += 0; + points3 = 0; } if(question_tf3.getText().startsWith("B") || question_tf3.getText().startsWith("b")) { - points += 4; + points3 = 4; } if(question_tf3.getText().startsWith("C") || question_tf3.getText().startsWith("c")) { - points += 10; + points3 = 10; } } } @@ -180,13 +185,13 @@ public class FitnessTest_M extends JFrame { public void actionPerformed(ActionEvent e) { if (e.getSource() == question4_confirm) { if(question_tf4.getText().startsWith("A") || question_tf4.getText().startsWith("a")) { - points += 0; + points4 = 0; } if(question_tf4.getText().startsWith("B") || question_tf4.getText().startsWith("b")) { - points += 4; + points4 = 4; } if(question_tf4.getText().startsWith("C") || question_tf4.getText().startsWith("c")) { - points += 10; + points4 = 10; } } } @@ -256,26 +261,26 @@ public class FitnessTest_M extends JFrame { float height = Float.parseFloat(height_tf.getText()); float weight = Float.parseFloat(weight_tf.getText()); int bmi = calculateBmi(height, weight); - if(bmi <= 15) points += 0; - if(bmi == 16) points += 1; - if(bmi == 17) points += 2; - if(bmi == 18) points += 3; - if(bmi == 19) points += 6; - if(bmi == 20) points += 8; - if(bmi == 21) points += 9; - if(bmi == 22) points += 10; - if(bmi == 23) points += 10; - if(bmi == 24) points += 9; - if(bmi == 25) points += 8; - if(bmi == 26) points += 7; - if(bmi == 27) points += 6; - if(bmi == 28) points += 5; - if(bmi == 29) points += 4; - if(bmi == 30) points += 4; - if(bmi == 31) points += 3; - if(bmi == 32) points += 2; - if(bmi == 33) points += 1; - if(bmi >= 34) points += 0; + if(bmi <= 15) points5 = 0; + if(bmi == 16) points5 = 1; + if(bmi == 17) points5 = 2; + if(bmi == 18) points5 = 3; + if(bmi == 19) points5 = 6; + if(bmi == 20) points5 = 8; + if(bmi == 21) points5 = 9; + if(bmi == 22) points5 = 10; + if(bmi == 23) points5 = 10; + if(bmi == 24) points5 = 9; + if(bmi == 25) points5 = 8; + if(bmi == 26) points5 = 7; + if(bmi == 27) points5 = 6; + if(bmi == 28) points5 = 5; + if(bmi == 29) points5 = 4; + if(bmi == 30) points5 = 4; + if(bmi == 31) points5 = 3; + if(bmi == 32) points5 = 2; + if(bmi == 33) points5 = 1; + if(bmi >= 34) points5 = 0; } } }); @@ -284,6 +289,22 @@ public class FitnessTest_M extends JFrame { frame.add(bmi_rechnen); frame.add(bmi_confirm); + totalscore_submit = new JButton("Gesammtergebnis"); + totalscore_submit.setBounds(1100, 200, 200, 150); + totalscore_submit.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if(e.getSource() == totalscore_submit) { + float sum = (points1+points2+points3+points4+points5)/5; + JOptionPane.showMessageDialog(null, + "Ihre Gesammtfitnesspunktzahl betraegt:\n" + sum, + "Testergebnis", + JOptionPane.WARNING_MESSAGE); + } + } + }); + + frame.add(totalscore_submit); + frame.setVisible(true); }