-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPoint.java
More file actions
54 lines (44 loc) · 1.12 KB
/
Point.java
File metadata and controls
54 lines (44 loc) · 1.12 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
54
public class Point {
private int x, y; // absis dan ordinat
// Constructor
// Set titik mula-mula ke (0, 0)
public Point() {
this.x = 0;
this.y = 0;
}
// Set titik mula-mula ke (x, y)
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getAbsis() {
return x;
}
public int getOrdinat() {
return y;
}
public void setAbsis(int x) {
this.x = x;
}
public void setOrdinat(int y) {
this.y = y;
}
// Mengubah titik dengan penambahan Point argumen
public void translate(Point p) {
this.x += p.x;
this.y += p.y;
}
// Mentranslasikan titik sebesar (x, y)
public void translate(int x, int y) {
this.x += x;
this.y += y;
}
// Menghasilkan jarak antara titik sekarang dengan Point argumen
public double distance(Point p) {
return Math.sqrt((this.x - p.x) * (this.x - p.x) + (this.y - p.y) * (this.y - p.y));
}
// Menuliskan titik ke layar dengan format "(x,y)"
public void print() {
System.out.println("(" + this.x + "," + this.y + ")");
}
}