package HinhHocKhongGian;

import java.util.Scanner;

public class Diem2D {
    private int x;
    private int y;

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    // Constructor

    public Diem2D() {
        x = y = 0;
    }

    public Diem2D(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public Diem2D(Diem2D D) {
        this.x = D.x;
        this.y = D.y;
    }

    // Method

    public void nhap() {
        Scanner input = new Scanner(System.in);
        System.out.print("Nhập x:");
        this.x = input.nextInt();
        System.out.print("Nhập y:");
        this.y = input.nextInt();
    }

    public void doiDiem(int dx, int dy) {
        this.x += dx;
        this.y += dy;
    }

    public void xuat() {
        System.out.print("(" + this.x + "," + this.y + ")");
    }

    public String xuatString()
    {
        return "(" + this.x + "," + this.y + ")";
    }

    public double tinhKhoangCach()
    {
        return tinhKhoangCach(new Diem2D());
    }

    public double tinhKhoangCach(Diem2D D)
    {
        return Math.round(Math.sqrt( Math.pow(this.x - D.x,2) + Math.pow(this.y - D.y,2))*100)/100;
    }

}