Browse Source

Perimeter of a Rectangle

remotes/origin/develop
fdai7460 2 years ago
parent
commit
51eb2c38e4
  1. 30
      src/main/java/src/TasksFrame.java
  2. 11
      src/test/java/src/TasksFrameTest.java

30
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) {

11
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);
}
}

Loading…
Cancel
Save