From 6254cee38051edccfe14201a43e8b8579a19e9b5 Mon Sep 17 00:00:00 2001 From: fdai6040 Date: Mon, 6 Feb 2023 23:06:42 +0100 Subject: [PATCH] new task "Durchschnitt" added --- src/main/java/src/TasksFrame.java | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index 4dc79ed..b8d47bb 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -87,6 +87,8 @@ public class TasksFrame extends JFrame { setupPI(100000); + setupDurchschnitt(); + setupEulerschePhiFunk(); setupQuersumme(); @@ -106,6 +108,66 @@ public class TasksFrame extends JFrame { } + private void setupDurchschnitt() { + + JPanel jPanel = setupPanel("Durchschnitt"); + + JButton button = new JButton("calculate"); + button.setVisible(true); + button.setBounds(10, 65, 100, 30); + button.setBackground(Color.BLUE); + + JTextField a = new JTextField(); + a.setBounds(10, 40, 30, 20); + a.setVisible(true); + a.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); + + JTextField b = new JTextField(); + b.setBounds(50, 40, 30, 20); + b.setVisible(true); + b.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); + + JTextField c = new JTextField(); + c.setBounds(90, 40, 30, 20); + c.setVisible(true); + c.setFont(new java.awt.Font("Arial", Font.BOLD, 12)); + + 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(); + Double val_a = Double.valueOf(texta); + Double val_b = Double.valueOf(textb); + Double val_c = Double.valueOf(textc); + double res = average(val_a, val_b, val_c); + jLabel.setText(String.valueOf(res)); + } + }); + } + + public double average(double a, double b, double c) { + + double sum = a + b + c; + double average = sum / 3; + double roundOff = Math.round(average * 100.0) / 100.0; + return roundOff; + + } + + + private void setupExponent() { JPanel jPanel = setupPanel("Potenzrechner");