Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MyPoint.java
- public class MyPoint {
- double x;
- double y;
- MyPoint() {
- x = y = 0;
- }
- MyPoint(double x, double y) {
- this.x = x;
- this.y = y;
- }
- public double getX() {
- return x;
- }
- public double getY() {
- return y;
- }
- public double distance(double x2, double y2) {
- double distance = Math.sqrt(Math.pow((x2 - x), 2) + Math.pow((y2 - y), 2));
- return distance;
- }
- public double distance(MyPoint obj) {
- double distance = Math.sqrt(Math.pow((obj.getX() - x), 2) + Math.pow((obj.getY() - y), 2));
- return distance;
- }
- }
- //TestMyPoint.java
- public class TestMyPoint {
- public static void main(String[] args) {
- MyPoint point1 = new MyPoint();
- MyPoint point2 = new MyPoint(-5, -5);
- MyPoint point3 = new MyPoint(10, 3);
- double distance1 = point1.distance(point2);
- System.out.println(distance1);
- double distance2 = point1.distance(10, 0);
- System.out.println(distance2);
- double distance3 = point2.distance(point3);
- System.out.println(distance3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement