Browse Source

Difference

remotes/origin/develop
fdai7460 2 years ago
parent
commit
de0accea73
  1. 46
      src/main/java/src/TasksFrame.java
  2. 18
      src/test/java/src/TasksFrameTest.java

46
src/main/java/src/TasksFrame.java

@ -69,6 +69,10 @@ public class TasksFrame extends JFrame {
setup5ModList(1, 20);
setupLeibnizR(1000);
setupDiff();
}
@ -129,6 +133,48 @@ public class TasksFrame extends JFrame {
jPanel.add(jLabel);
}
public void setupDiff(){
JPanel jPanel = setupPanel("Difference");
JTextField x = new JTextField();
x.setBounds(10,50,30,20);
x.setVisible(true);
JTextField y = new JTextField();
y.setBounds(50,50,30,20);
y.setVisible(true);
JTextField result = new JTextField();
result.setBounds(100,50,30,20);
result.setVisible(true);
JButton difference = new JButton("Difference");
difference.setBounds(10,90,100,30);
difference.setVisible(true);
difference.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String textx = x.getText();
String texty = y.getText();
Integer val_x = Integer.valueOf(textx);
Integer val_y = Integer.valueOf(texty);
Integer res = calcDiff(val_x, val_y);
result.setText(String.valueOf(res));
}
});
jPanel.add(x);
jPanel.add(y);
jPanel.add(result);
jPanel.add(difference);
}
public int calcDiff(int a, int b) {
return a-b;
}
private void setupSum() {
JPanel jPanel = setupPanel("Summe");

18
src/test/java/src/TasksFrameTest.java

@ -12,4 +12,20 @@ class TasksFrameTest {
double x = tasksFrame.setupLeibnizR(100000);
assertEquals(Math.PI/4, x, 0.00001, "Die Werte sind unterschiedlich. Soll: 0.785 Ist:" +x);
}
}
@Test
void setupDiff(){
TasksFrame frame = new TasksFrame();
int diff = frame.calcDiff(6, 7);
assertEquals(-1, diff);
int diff2 = frame.calcDiff(0,0);
assertEquals(0,diff2);
int diff3 = frame.calcDiff(12, 8);
assertEquals(4, diff3);
}
}
Loading…
Cancel
Save