Created
August 13, 2019 13:24
-
-
Save 0ryant/14784edf7fd645b63f61a841a7f51031 to your computer and use it in GitHub Desktop.
Java - Coding Challenge - Classes; Co-ordinates Distance Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Point { | |
// Params | |
private int x; | |
private int y; | |
// Constructors | |
public Point() { | |
this(0,0); | |
} | |
public Point(int x, int y) { | |
this.x = x; | |
this.y = y; | |
} | |
// Getters | |
public int getX() { | |
return x; | |
} | |
public int getY() { | |
return y; | |
} | |
// Setters | |
public void setX(int x) { | |
this.x = x; | |
} | |
public void setY(int y) { | |
this.y = y; | |
} | |
// Extra Methods | |
public double distance (){ | |
return distance(0,0); | |
} | |
public double distance(int x,int y){ | |
return Math.sqrt(Math.pow(this.x - x, 2) + Math.pow(this.y - y, 2)); | |
} | |
public double distance(Point newPoint){ | |
return distance(newPoint.x,newPoint.y); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment