-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDistance_TwoPoints.java
More file actions
53 lines (38 loc) · 1.05 KB
/
Copy pathDistance_TwoPoints.java
File metadata and controls
53 lines (38 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.Scanner;
class Point {
float x, y;
void setPoint(float x1, float y1) {
x = x1;
y = y1;
}
void showPoint() {
System.out.println("(" + x + "," + y + ")");
}
double findDistance(Point p) {
double f = Math.sqrt((Math.pow((p.x - x), 2)) + (Math.pow((p.y - y), 2)));
return f;
}
}
class Distance_TwoPoints {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
Point a = new Point();
System.out.println("Enter the coordinates for point 1:");
float k = in.nextFloat();
float l = in.nextFloat();
a.setPoint(k, l);
System.out.print("Point 1 is:");
a.showPoint();
Point b = new Point();
System.out.println("Enter the coordinates for point 2:");
int k1 = in.nextInt();
int l1 = in.nextInt();
b.setPoint(k1, l1);
System.out.print("Point 2 is:");
b.showPoint();
double d = a.findDistance(b);
System.out.print("Distance between point 1 and point 2 is approximately: " + d);
in.close();
}
}