Trying to learn Java - Programming too many bloody bugs

I've been trying to program a calculator, however, I keep running into errors e.g. java:77: error: non-static variable this cannot be referenced from a static context this.resDifference = Calculator.subTwoNumbers();. incompatible types: Calculator cannot be converted to double this.resDifference = Calculator.subTwoNumbers();.

class Calculator {

private ComplexNumber compNum1;

private ComplexNumber compNum2;

public Calculator(ComplexNumber number1, ComplexNumber number2){

compNum1 = number1;

compNum2 = number2;

}

public Calculator addTwoNumbers(){

double real = compNum1.real + compNum2.real;

double imaginary = compNum1.imaginary + compNum2.imaginary;

return new ComplexNumber(real, imaginary);

}

public Calculator subTwoNumbers(){

double real = compNum1.real - compNum2.real;

double imaginary = compNum1.imaginary - compNum2.imaginary;

return new ComplexNumber(real, imaginary);

}

public...

Read More »

By: StackOverFlow - Monday, 16 April

Related Posts