diff --git a/src/main/java/src/TasksFrame.java b/src/main/java/src/TasksFrame.java index bf36c1d..e9973d0 100644 --- a/src/main/java/src/TasksFrame.java +++ b/src/main/java/src/TasksFrame.java @@ -321,6 +321,28 @@ public class TasksFrame extends JFrame { jPanel.add(area); jPanel.add(areaRes); + JButton perimeter = new JButton("Calculate perimeter"); + perimeter.setVisible(true); + perimeter.setBounds(0, 110, 180,30); + + JTextField perimeterRes = new JTextField(); + perimeterRes.setBounds(200,110,30,20 ); + perimeterRes.setVisible(true); + perimeter.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String texta = a.getText(); + String textb = b.getText(); + Integer val_a = Integer.valueOf(texta); + Integer val_b = Integer.valueOf(textb); + Integer res = calcPerimeter(val_a, val_b); + perimeterRes.setText(String.valueOf(res)); + } + }); + + jPanel.add(perimeterRes); + jPanel.add(perimeter); + } public int calcArea(int a, int b) @@ -329,6 +351,13 @@ public class TasksFrame extends JFrame { return area; } + public int calcPerimeter(int a, int b) + { + int perimeter = 2 * (a+b); + return perimeter; + } + + public void setupSumFromTo(){ @@ -365,6 +394,7 @@ public class TasksFrame extends JFrame { jPanel.add(b); jPanel.add(result); jPanel.add(sumFromTo); + } public int sumCalc(int from, int to) { diff --git a/src/test/java/src/TasksFrameTest.java b/src/test/java/src/TasksFrameTest.java index c7de36d..d31ce6b 100644 --- a/src/test/java/src/TasksFrameTest.java +++ b/src/test/java/src/TasksFrameTest.java @@ -80,6 +80,17 @@ class TasksFrameTest { } + @Test + void setupPerimeter() + { + TasksFrame tasksFrame = new TasksFrame(); + int p1 = tasksFrame.calcPerimeter(3,5); + assertEquals(16, p1); + int p2= tasksFrame.calcArea(0,7); + assertEquals(0,p2); + + } + }