Browse Source

Area of a Rectangle

remotes/origin/develop
fdai7460 2 years ago
parent
commit
e6d3c931fc
  1. 72
      src/main/java/src/TasksFrame.java
  2. 23
      src/test/java/src/TasksFrameTest.java

72
src/main/java/src/TasksFrame.java

@ -17,13 +17,13 @@ public class TasksFrame extends JFrame {
super("Unsere kleinen Tasks"); super("Unsere kleinen Tasks");
setVisible(true); setVisible(true);
setBounds(810,200, 300, 600);
setPreferredSize(new Dimension(300, 600));
setBounds(810,200, 400, 600);
setPreferredSize(new Dimension(400, 600));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false); setResizable(false);
JPanel root = new JPanel(); JPanel root = new JPanel();
root.setBounds(0, 0, 300, 600);
root.setBounds(0, 0, 400, 600);
root.setVisible(true); root.setVisible(true);
setContentPane(root); setContentPane(root);
@ -34,7 +34,7 @@ public class TasksFrame extends JFrame {
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS)); container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
jScrollPane = new JScrollPane(container, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); jScrollPane = new JScrollPane(container, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jScrollPane.setPreferredSize(new Dimension(300, 600));
jScrollPane.setPreferredSize(new Dimension(400, 600));
root.add(jScrollPane); root.add(jScrollPane);
} }
@ -51,7 +51,7 @@ public class TasksFrame extends JFrame {
JLabel jLabel = new JLabel(header); JLabel jLabel = new JLabel(header);
jLabel.setVisible(true); jLabel.setVisible(true);
jLabel.setBounds(3, 3, 160, 20);
jLabel.setBounds(3, 3, 300, 20);
panel.add(jLabel); panel.add(jLabel);
@ -66,6 +66,8 @@ public class TasksFrame extends JFrame {
setupDiff(); setupDiff();
setupArea();
setupSumFromTo(); setupSumFromTo();
setup5ModList(1, 20); setup5ModList(1, 20);
@ -207,6 +209,64 @@ public class TasksFrame extends JFrame {
return a-b; return a-b;
} }
public void setupArea()
{
JPanel jPanel = setupPanel("Area and perimeter of a Rectangle:");
JLabel jL1 = new JLabel();
jL1.setText("Side a:");
jL1.setVisible(true);
jL1.setBounds(0,20,50,30);
JLabel jL2 = new JLabel();
jL2.setText("Side b:");
jL2.setVisible(true);
jL2.setBounds(0,40,50,30);
JTextField a = new JTextField();
a.setVisible(true);
a.setBounds(50,25,30,20);
JTextField b = new JTextField();
b.setVisible(true);
b.setBounds(50,45,30,20);
JButton area = new JButton("Calculate area");
area.setVisible(true);
area.setBounds(0, 80, 180,30);
JTextField areaRes = new JTextField();
areaRes.setBounds(200,80,30,20 );
areaRes.setVisible(true);
area.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 = calcArea(val_a, val_b);
areaRes.setText(String.valueOf(res));
}
});
jPanel.add(jL1);
jPanel.add(jL2);
jPanel.add(a);
jPanel.add(b);
jPanel.add(area);
jPanel.add(areaRes);
}
public int calcArea(int a, int b)
{
int area = a * b;
return area;
}
public void setupSumFromTo(){ public void setupSumFromTo(){
@ -294,4 +354,6 @@ public class TasksFrame extends JFrame {
return sum; return sum;
} }
} }

23
src/test/java/src/TasksFrameTest.java

@ -7,14 +7,16 @@ import static org.junit.jupiter.api.Assertions.*;
class TasksFrameTest { class TasksFrameTest {
@Test @Test
void setupLeibnizR() {
void setupLeibnizR()
{
TasksFrame tasksFrame = new TasksFrame(); TasksFrame tasksFrame = new TasksFrame();
double x = tasksFrame.setupLeibnizR(100000); double x = tasksFrame.setupLeibnizR(100000);
assertEquals(Math.PI/4, x, 0.00001, "Die Werte sind unterschiedlich. Soll: 0.785 Ist:" +x); assertEquals(Math.PI/4, x, 0.00001, "Die Werte sind unterschiedlich. Soll: 0.785 Ist:" +x);
} }
@Test @Test
void setupDiff(){
void setupDiff()
{
TasksFrame frame = new TasksFrame(); TasksFrame frame = new TasksFrame();
int diff = frame.calcDiff(6, 7); int diff = frame.calcDiff(6, 7);
assertEquals(-1, diff); assertEquals(-1, diff);
@ -25,7 +27,8 @@ class TasksFrameTest {
} }
@Test @Test
void setupSumm(){
void setupSumm()
{
TasksFrame frame = new TasksFrame(); TasksFrame frame = new TasksFrame();
int sum1 = frame.calcSumm(23, 11); int sum1 = frame.calcSumm(23, 11);
assertEquals(34, sum1); assertEquals(34, sum1);
@ -36,7 +39,8 @@ class TasksFrameTest {
} }
@Test @Test
void setupSumFromTo(){
void setupSumFromTo()
{
TasksFrame frame = new TasksFrame(); TasksFrame frame = new TasksFrame();
int p1= frame.sumCalc(1,5); int p1= frame.sumCalc(1,5);
assertEquals(15,p1); assertEquals(15,p1);
@ -46,6 +50,17 @@ class TasksFrameTest {
assertEquals(3,p3); assertEquals(3,p3);
} }
@Test
void setupArea()
{
TasksFrame tasksFrame = new TasksFrame();
int p1 = tasksFrame.calcArea(3,5);
assertEquals(15, p1);
int p2= tasksFrame.calcArea(0,7);
assertEquals(0,p2);
}
} }

Loading…
Cancel
Save