Question: public class ComplexNumber { private float a; private float b; public ComplexNumber(float a, float b) { this.a = a; this.b = b; } // 4

 public class ComplexNumber { private float a; private float b; public

public class ComplexNumber { private float a; private float b; public ComplexNumber(float a, float b) { this.a = a; this.b = b; } // 4 methods for add sub mult and div public ComplexNumber add(ComplexNumber c) { ComplexNumber newComplex; float newA = a + c.getA(); float newB = b + c.getB(); newComplex = new ComplexNumber(newA, newB); return newComplex; } public ComplexNumber sub(ComplexNumber c) { ComplexNumber newComplex; float newA = a - c.getA(); float newB = b - c.getB(); newComplex = new ComplexNumber(newA, newB); return newComplex; } public ComplexNumber mult(ComplexNumber c) { ComplexNumber newComplex; float newA = a * c.getA() - b * c.getB(); float newB = b * c.getA() + a * c.getB(); newComplex = new ComplexNumber(newA, newB); return newComplex; } public ComplexNumber div(ComplexNumber c) { ComplexNumber newComplex; float mag = (float) Math.sqrt(c.getA() * c.getA() + c.getB() * c.getB()); float newA = (a * c.getA() + b * c.getB()) / mag; float newB = (b * c.getA() - a * c.getB()) / mag; newComplex = new ComplexNumber(newA, newB); return newComplex; } // getters for A and B public float getA() { return a; } public float getB() { return b; } // equals method public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ComplexNumber that = (ComplexNumber) o; return Float.compare(that.a, a) == 0 && Float.compare(that.b, b) == 0; } // toString() method public String toString() { if (b   Writing the JUnit Tester In a separate file, ComplexNumberTests.java, implement a JUnitTester for your ComplexNumber class using JUnit 4. You should provide at least one @Test method for each of the public methods in ComplexNumber. Each test method should verify the correctness of the method it is testing using multiple ComplexNumber instances as input. Compile and run the test class (using org.junit.runner.JUnitCore) to verify that all your tests pass. Be sure to test for a wide variety of input combinations to ensure adequate testing. Take a look at the JUnit documentation online to discover new interesting testing techniques. Tip: when testing your program to make sure your calculations are correct, use www.wolframalpha.com to verify your calculations

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!