(Java)无法设置X和Y点

时间:2016-02-15 03:27:24

标签: java class math

到目前为止,我在我的Point类

中有这个
//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;
}

我正在尝试创建另一个名为segment的类,它将使用我的Point类,在该类中我有这个

private Point Point1;
private Point Point2;

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

然而,我收到一个错误,说它期望在每个X和Y点之间有一个“)”。

为什么我会收到该错误?在我的点类中,我设置它以便接受新的X和Y并将它们设置为新点。所以在我的段类中,我传递的是X和Y。

请帮助我或澄清我做错了什么。谢谢。

1 个答案:

答案 0 :(得分:3)

您需要关键字new和类名。此

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

应该是

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