For my assignment I am to create 5 Classes in a hierarchy that extends Number. I am to create methods of addition subtraction multiplication and devision for each of the classes that has two parameters and a return type of the class.
The method grammar is the same for each class. They all cause crashes in the interactions pane of Dr. Java and return no errors.
How do I resolve this?
public class ComplexN extends Number{
private double value1;
private double value2;
public ComplexN(double real, double imaginary){
this.value1=real;
this.value2=imaginary;
}
public double getRealPart(){
return value1;
}
public double getImaginaryPart(){
return value2;
}
public static ComplexN add(ComplexN a, ComplexN b){
ComplexN sum = new ComplexN((a.getRealPart()+b.getRealPart()),(a.getImaginaryPart()+b.getImaginaryPart()));
return sum;
}
}