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

📄 point.java

📁 BOOK:Beginning Algorithms Code Examples
💻 JAVA
字号:
package com.wrox.algorithms.geometry;/** * Represents a single point in the geometric coordinate system. * Objects of this class are immutable. */public class Point {    private final double _x;    private final double _y;    /**     * Only supported constructor.     * @param x x-coordinate for the point.     * @param y y-coordinate for the point.     */    public Point(double x, double y) {        _x = x;        _y = y;    }    public double getX() {        return _x;    }    public double getY() {        return _y;    }    public double distance(Point other) {        assert other != null : "other can't be null";        double rise = getY() - other.getY();        double travel = getX() - other.getX();        return Math.sqrt(rise * rise + travel * travel);    }    public int hashCode() {        return (int) (_x * _y);    }    public boolean equals(Object obj) {        if (this == obj) {            return true;        }        if (obj == null || obj.getClass() != getClass()) {            return false;        }        Point other = (Point) obj;        return getX() == other.getX() && getY() == other.getY();    }}

⌨️ 快捷键说明

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