Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package prj12062021;
- public class Point {
- private double x;
- private double y;
- // constructor 1
- public Point() {
- this.x = 0;
- this.y = 0;
- }
- // constructor 2
- public Point(double x, double y) {
- this.x = x;
- this.y = y;
- }
- // getters
- public double getX() {
- return this.x;
- }
- public double getY() {
- return this.y;
- }
- // setters
- public void setX(double x) {
- this.x = x;
- }
- public void setY(double y) {
- this.y = y;
- }
- public void print() {
- System.out.println("(" + x + ", " + y + ")");
- }
- public double distance(Point other) {
- double dx = this.x - other.x;
- double dy = this.y - other.y;
- return Math.sqrt(dx * dx + dy * dy);
- }
- @Override
- public boolean equals(Object obj) {
- Point p = (Point) obj;
- return (this.x == p.x && this.y == p.y);
- }
- @Override
- public String toString() {
- return "(" + x + ", " + y + ")";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement