Skip to content

Instantly share code, notes, and snippets.

@pteacher
Created October 25, 2017 13:21
Show Gist options
  • Save pteacher/8f055c750f12969dbfa6a201aaba74b1 to your computer and use it in GitHub Desktop.
Save pteacher/8f055c750f12969dbfa6a201aaba74b1 to your computer and use it in GitHub Desktop.
package com.company;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
Point p1 = new Point();
p1.setXY();
p1.getXY();
p1.move(2, 0);
p1.getXY();
Point p2 = new Point();
p2.setXY(0, 0);
p2.getXY();
System.out.println("Distance: " + p2.getDistance(p1));
}
}
class Point {
double x;
double y;
void setXY() {
Scanner in = new Scanner(System.in);
x = in.nextDouble();
y = in.nextDouble();
}
void setXY(double x, double y) {
this.x = x;
this.y = y;
}
void getXY() {
System.out.println("x: " + x + " y: " + y);
}
void move(double dx, double dy) {
x += dx;
y += dy;
}
double getDistance(Point p2) {
return Math.sqrt((p2.x - x)*(p2.x - x) + (p2.y - y)*(p2.y - y));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment