I'm getting an error I don't quite understand. My goal is to create a simple program that adds, subtracts, multiplies, and divides complex numbers. My ComplexNumber class compiles correctly, but when I try to compile with the first test case of my Tester class it gives me this error:
ComplexNumberTest.java:37: error: method add in class ComplexNumber cannot be applied to given types; assertEquals(test1.add()==0); ^ required: ComplexNumber found: no argument reason: actual and formal arguments differ in length
This is my add method
import java.lang.ArithmeticException;
public class ComplexNumber{
private float a; //real
private float b; //imaginary
public ComplexNumber(float a,float b)
{
this.a = a;
this.b = b;
} //end constructor
public ComplexNumber add(ComplexNumber otherNumber){
ComplexNumber newComplex;
float newA = a + otherNumber.getA();
float newB = b + otherNumber.getB();
newComplex = new ComplexNumber(newA, newB);
return newComplex;
}//end add
This is my Tester class
import junit.framework.TestCase;
public class ComplexNumberTest extends TestCase{
private ComplexNumber test1;
private ComplexNumber test2;
private ComplexNumber test3;
private ComplexNumber test4;
private ComplexNumber test5;
public void setUp(){
test1 = new ComplexNumber (1,-1);
test2 = new ComplexNumber(2,2);
test3 = new ComplexNumber(0,2);
test4 = new ComplexNumber(3,1);
test5 = new ComplexNumber(4,4);
}//end set up
/**
* A method used to test the add method.
* add two Complex numbers together
* (ai+bi)=a+bi
*
**/
public void testAdd()
{
assertEquals(test1.add()==0);
//assertTrue(test2.add()==4);
//assertEquals(test3.add()==2);
//assertEquals(test4.add()==3);
//assertEquals(test5.add()==8);
}//end testAddition
I feel like the solution is fairly simple and I've just been staring at it for too long. Thanks for any advice.