【发布时间】:2016-02-05 11:32:37
【问题描述】:
我已经阅读了其他一些问题,但似乎仍然无法弄清楚如何让我的工作,感谢任何帮助。我到目前为止的代码如下。我希望能够调用一个 newPointParameters 来创建一个新类。
public class Lab4ex1 {
public static void main(String[] args) {
System.out.println("" + 100);
new newPointParameter(42,24);
}
class Point {
private double x = 1;
private double y = 1;
public double getx() {
return x;
}
public double gety() {
return y;
}
public void changePoint(double newx, double newy) {
x = newx;
y = newy;
}
public void newPointParameters(double x1, double y1) {
this.x = x1;
this.y = y1;
}
public void newPoint() {
this.x = 10;
this.y = 10;
}
public double distanceFrom(double x2, double y2) {
double x3 = x2 - this.x;
double y3 = y2 - this.y;
double sqaureadd = (y3 * y3) + (x3 * x3);
double distance = Math.sqrt(sqaureadd);
return distance;
}
}
}
【问题讨论】:
-
阅读更多关于 JAVA 类方面的“构造函数”,您将能够弄清楚。现在,您可以将方法
newPointParameters和newPoint的名称更改为Point。从方法签名中删除void并在main方法中添加Point p = new Point(42, 24)
标签: java class constructor main