Question: Question 2. Write your solution in file Q2.java. Use Q2Test.java to test your solution. Write two methods named findArea that take side lengths of a

Question 2. Write your solution in file Q2.java. Use Q2Test.java to test your solution. Write two methods named findArea that take side lengths of a square or a rectangle as parameters. findArea method must return the area of a square if there is only one parameter. If there are two parameters, findArea method returns the area of a rectangle.

Example

findArea(2) ?> 4

findArea(3) ?> 9

findArea (2 , 3) ?> 6

findArea (4 , 5) ?> 20

Q2TEST.JAVA

import java.io.IOException; import java.io.PrintWriter;

import org.junit.Rule; import org.junit.Test; import org.junit.rules.TestWatcher; import org.junit.runner.Description; import org.junit.runner.JUnitCore; import org.junit.runner.Result;

public class Q2Test extends student.TestCase {

static JUnitCore junitCore; static Class testClasses;

@Test public void testCase1() { assertEquals(16, Q2.findArea(4)); }

@Test public void testCase2() { assertEquals(144, Q2.findArea(12)); }

@Test public void testCase3() { assertEquals(280, Q2.findArea(20,14)); }

@Test public void testCase4() { assertEquals(3400, Q2.findArea(100,34)); }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!