So I have designed my program but am stuck on one function.
The following is an excerpt from my class:

public class SqrXY
{
    public void SqrXY (double x, double y)
    {
        xaxis = x;
        yaxis = y;
    }
    public double addition ()
    {
        //this is what I am stuck on
    }
}

And excerpt from my run class:

SqrXY instance1 = new SqrXY (4.0, 2.0);
SqrXY instance2 = new SqrXY (6.0, 3.0);
SqrXY instance3 = instance1.addition(instance2); //instance3 is initialized as (10.0, 5.0)

So I need to create an addition function which will add the values of the already initialized objects. This is the last part of my assignment and I've been stuck on it for a couple days any help would be appreciated.

Wouldn't something like this work?

sqrXY instance3 = new sqrXY(instance1.xaxis+instance2.xaxis, instance1.yaxis+instance2.yaxis);

I'm just guessing here by the way, I'm a student myself...

But I have to make a function named addition to go in the SqrXY class this doesn't do that.

SqrXY instance3 = instance1.addition(instance2);

Err I keep saying function but the term in Java is Method.

Never mind figured it out on my own :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.