Paincakes
Paincakes

Reputation: 147

(Java) Cannot Set X and Y Points

So far I have this in my Point class

//Data
private int x;
private int y;

//Default Constructor
public Point ( )
{
    this.x = 0;
    this.y = 0;
}

//Parameterized Constructor.
public Point (int newX , int newY)
{
    this.x = newX;
    this.y = newY;
}

//Copy Constructor.
public Point (Point other)
{
    this.x = other.x;
    this.y = other.y;
}

I am trying to create another class called segment that will use my Point class, and in that class I have this

private Point Point1;
private Point Point2;

public Segment ( )
{
    this.Point1 = (0, 0);
    this.Point2 = (7, 7);
}

However, I am getting an error saying that it was expecting a ")" right between each X and Y point.

Why am I getting that error? In my point class, I have it set up so that it will accept a new X and Y and set those as the new point. So in my segment class, I am passing in an X and Y.

Please help me or clarify what I am doing wrong. Thank you.

Upvotes: 0

Views: 55

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201537

You need the keyword new and the classname. This

this.Point1 = (0, 0);
this.Point2 = (7, 7);

should be something like

this.Point1 = new Point(0, 0);
this.Point2 = new Point(7, 7);

Upvotes: 3

Related Questions