Browse Source

Runde Summe Function added, die die Summe der auf Zehner gerundeten Werte von a, b und c zurückgibt

remotes/origin/develop
fdai6040 2 years ago
parent
commit
a939b97992
  1. 61
      src/main/java/src/TasksFrame.java

61
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");

Loading…
Cancel
Save