Hello,
I was trying to get hold of arrays and read lots of stuff.
So when i started coding, i got an error message saying incompatible types. I checked with general compliance and it should be ok. Maybe netbeans causing it?
Anyway, any kind of help will be appreciated

public class Point implements Cloneable
{

    // instance variables 

    double points [];
    double x;
    double y;
    /**
     * Constructor for objects of class Position
     */
    public Point()           // This is a no-argument constructor
    {
    // initialise instance variables to zero
    double points []  = {0, 0};
    double x = 0;
    double y = 0;

    }

    /**
     * setLocation()
     * This method sets initial location of a point in 2D
     *
     * @param  x,y all doubles 
     * @return   array points
     */
    public double setLocation( double x, double y)
    {
        // Temporary variables that take values from the user input
        
        points [0] = x;
        points [1] = y;

        System.out.println("Initial location of points is: " + points);
        return points; 
    }

}

It has nothing to do with NetBeans:

/**
     * setLocation()
     * This method sets initial location of a point in 2D
     *
     * @param  x,y all doubles
     * @return   array points
     */
    public double setLocation( double x, double y)
    {
        // Temporary variables that take values from the user input

        points [0] = x;
        points [1] = y;

        System.out.println("Initial location of points is: " + points);
        return points;
    }

points is an ARRAY of doubles. This function says it is returning a single double. You can't do that. If you want to return an array of doubles, do this:

public double[] setLocation( double x, double y)

Dear,

I think you should have to refere some Object-Oriented Programming books before submitting your problems.

A code fragment is meaningless.

public Point()           // This is a no-argument constructor
    {
    // initialise instance variables to zero
    double points []  = {0, 0};
    double x = 0;
    double y = 0;

     You are initializing local variables not an instance datamembers.
    }

Another problem with setLocation Method

/**
 * setLocation()
 * This method sets initial location of a point in 2D
 *
 * @param  x,y all doubles 
 * @return   array points
 */
public double setLocation( double x, double y)
{
    // Temporary variables that take values from the user input

    points [0] = x;
    points [1] = y;

    System.out.println("Initial location of points is: " + points);
    return points; 
}

Return type must be an array of double as per definition of setLocation Method - That is the reason, you got error message when you compile your code.

Please be careful before you post your problem.

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.