From 1fb4d1648ca895babe2a5a7679b061f872e89608 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 12:53:27 +0100 Subject: [PATCH 1/2] kgV Test --- src/test/java/src/TasksFrameTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index 5eef25f..ea4a96b 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -115,6 +115,17 @@ class TasksFrameTest { } + @Test + void test_kgV(){ + TasksFrame tasksFrame = new TasksFrame(); + int a = tasksFrame.kgV(5, 8); + assertEquals(40, a); + int b = tasksFrame.kgV(28, 64); + assertEquals(448, b); + int c = tasksFrame.kgV(35, 70); + assertEquals(70, c); + } + } From a939b97992b9b96ecaf8be9f5ce0de74ee1332f3 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Thu, 2 Feb 2023 13:48:33 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Runde=20Summe=20Function=20added,=20die=20d?= =?UTF-8?q?ie=20Summe=20der=20auf=20Zehner=20gerundeten=20Werte=20von=20a,?= =?UTF-8?q?=20b=20und=20c=20zur=C3=BCckgibt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/src/TasksFrame.java | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index f01a0b0..39b80f9 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -80,9 +80,70 @@ public class TasksFrame extends JFrame { setupQuersumme(); setupKgV(); + setupRoundSum(); } + private void setupRoundSum() { + JPanel jPanel = setupPanel("Runde Summe"); + + JButton button = new JButton("round sum"); + button.setVisible(true); + button.setBounds(10, 65, 100, 30); + + JTextField a = new JTextField(); + a.setBounds(10, 40, 30, 20); + a.setVisible(true); + + JTextField b = new JTextField(); + b.setBounds(50, 40, 30, 20); + b.setVisible(true); + + JTextField c = new JTextField(); + c.setBounds(90, 40, 30, 20); + c.setVisible(true); + + JLabel jLabel = new JLabel(); + jLabel.setVisible(true); + jLabel.setBounds(10,90,60,30); + + jPanel.add(button); + jPanel.add(a); + jPanel.add(b); + jPanel.add(c); + jPanel.add(jLabel); + + button.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String texta = a.getText(); + String textb = b.getText(); + String textc = c.getText(); + Integer val_a = Integer.valueOf(texta); + Integer val_b = Integer.valueOf(textb); + Integer val_c = Integer.valueOf(textc); + int res = roundSum(val_a, val_b, val_c); + jLabel.setText(String.valueOf(res)); + } + }); + } + + public int roundSum(int a, int b, int c) { + + return runde10(a) + runde10(b) + runde10(c); + + } + + public int runde10(int n) { + if (n % 10 >= 5) { + return n + 10 - n % 10; + } + else { + return n - n % 10; + } + } + + private void setupKgV() { JPanel jPanel = setupPanel("kgV");