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"); 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); + } + }