I want my main class to print a message when I call it, for example:
Complex x = new Complex(1, 20);
System.out.println(x);
and with that, there will be a message.
I tried creating a function called "messages". For example I have:
public Complex add(Complex op){
Complex x=new Complex(this.a, this.b);
x.a+=op.a;
x.b+=op.b;
return x.messages("Random Message");
}
Although this does work, I want for it to be:
public Complex add(Complex op){
Complex x=new Complex(this.a, this.b);
x.a+=op.a;
x.b+=op.b;
return x;
}
without having to use a secondary function so back in the main class:
Complex y=new Complex(5, 8);
Complex z=new Complex(15,6);
System.out.println(y.add(z));
it will make a message appear. Thank you in advance!