⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 point.java

📁 卡内基梅隆大学的网上教程 ssd3第二单元源码
💻 JAVA
字号:
package unitTwo;

/**
 * This class models a point in the Cartesian plane.
 *
 * @author iCarnegie
 * @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("pointOne: ");
        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());
        
        System.out.println("pointTwo: ");
        System.out.println("x: " + pointTwo.getX());
        System.out.println("y: " + pointTwo.getY());
    }

    /**
     * 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)  {

        this.x = initialX;
        this.y = initialY;

        Point.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 Point.numberOfInstances;
    }

    /**
     * Returns the x coordinate of this point.
     *
     * @return the x coordinate of this point.
     */
    public int  getX()  {

        return this.x;
    }

    /**
     * Returns the y coordinate of this point.
     *
     * @return the y coordinate of this point.
     */
    public int  getY()  {

        return this.y;
    }

    /**
     * Modifies the x coordinate of this point.
     *
     * @param newX  the new x coordinate
     */
    public void  setX(int  newX)  {

        this.x = newX;
    }

    /**
     * Modifies the y coordinate of this point.
     *
     * @param newY  the new y coordinate
     */
    public void  setY(int  newY)  {

        this.y = newY;
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -