Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Point {
- static private int count=0;
- private double x;
- private double y;
- public Point(double x, double y) {
- this.x=x;
- this.y=y;
- count++;
- System.out.println("Total created Points is " + count);
- }
- public double getX() {
- return x;
- }
- public void setX(double x) {
- this.x = x;
- }
- public double getY() {
- return y;
- }
- public void setY(double y) {
- this.y = y;
- }
- public double distance(Point p) {
- // return Math.sqrt(Math.pow(this.x-p.x, 2) + Math.pow(this.y-p.y, 2));
- double dx = this.x -p.x;
- double dy = this.y-p.y;
- dx = Math.pow(dx, 2);
- dy = Math.pow(dy,2);
- return Math.sqrt(dx+dy);
- }
- public Point middle(Point p) {
- double xmid = (this.x+p.x) / 2;
- double ymid =(this.y+p.y)/2;
- Point mid = new Point(xmid, ymid);
- return mid;
- }
- @Override
- public String toString() {
- return "(" + this.x + ", " + this.y + ")";
- }
- public static int getCount() {
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement