Search code examples
javacrashdrjava

Addition method causing IDE crash, no error code


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;
  }
}

Solution

  • After consulting with my Professor I have determined the problem.

    Dr. Java has a compatibility issue with Java 6.0 that causes a security error when you print the value of an object without explicitly using toString().

    so using:

    (a.add(a,b)).toString() 
    

    instead of:

    a.add(a,b)
    

    or similarly:

    a.toString()
    

    instead of:

    a
    

    ...will solve the problem in the short run. Also having the class extend Object instead of Number will patch this bug.