📄 point.java
字号:
/**
* This class models a point in the Cartesian plane.
*
* @author author name
* @version 1.0.0
*/
public class Point {
/* Number of instances created */
private static int numberOfInstances = 0;
/* x coordinate of this point*/
private int x;
/* y coordinate of this point*/
private int y;
/**
* Test driver for class <code>Point</code>.
*
* @param args not used
*/
public static void main(String[] args) {
Point pointOne = new Point(10, 100);
System.out.println("x: " + pointOne.getX());
System.out.println("y: " + pointOne.getY());
pointOne.setX(20);
pointOne.setY(200);
System.out.println("new x: " + pointOne.getX());
System.out.println("new y: " + pointOne.getY());
System.out.println("Instances before PointTwo is created: " +
Point.getNumberOfInstances());
Point pointTwo = new Point(20, 200);
System.out.println("Instances after PointTwo is created: " +
Point.getNumberOfInstances());
}
/**
* Creates a <code>Point</code> object and increments the
* number of instances.
*
* @param initialX the x coordinate
* @param initialY the y coordinate
*/
public Point(int initialX, int initialY) {
x = initialX;
y = initialY;
numberOfInstances++;
}
/**
* Returns the number of <code>Point</code> instances that
* have been created.
*
* @return the number of <code>Point</code> instances that
* have been created.
*/
public static int getNumberOfInstances() {
return numberOfInstances;
}
/**
* Returns the x coordinate of this point.
*
* @return the x coordinate of this point.
*/
public int getX() {
return x;
}
/**
* Returns the y coordinate of this point.
*
* @return the y coordinate of this point.
*/
public int getY() {
return y;
}
/**
* Modifies the x coordinate of this point.
*
* @param newX the new x coordinate
*/
public void setX(int newX) {
x = newX;
}
/**
* Modifies the y coordinate of this point.
*
* @param newY the new y coordinate
*/
public void setY(int newY) {
y = newY;
}
/**
* Overrides {@link Object#equals(Object)}.
* <p>
* Two <code>Point</code> objects are equal if their x and y
* coordinates are the same.
* </p>
*
* @param object object which this <code>Point</code> is
* compared.
* @return <code>true</code> if the x and y coordinates of
* this <code>Point</code> are equal to the x and y
* coordinates of the argument; <code>false</code>
* otherwise.
*/
// public boolean equals(Object object) {
//
// if (object instanceof Point) {
//
// Point point = (Point) object;
//
// return point.getX() == getX() && point.getY() == getY();
//
// } else {
//
// return false;
// }
// }
/**
* Overrides {@link Object#toString()}.
* <p>
* Returns a string representation of this <code>Point</code>
* object.
* </p>
*
* @return a string representation of this <code>Point</code>
* object.
*/
// public String toString() {
//
// return "(" + getX() + "," + getY() + ")";
// }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -