-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMovablePoint.java
More file actions
39 lines (31 loc) · 780 Bytes
/
MovablePoint.java
File metadata and controls
39 lines (31 loc) · 780 Bytes
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
package src.ex5;
public class MovablePoint implements Movable {
int x, y, xSpeed, ySpeed; // package access
public MovablePoint(int x, int y, int xSpeed, int ySpeed) {
this.x = x;
this.y = y;
this.xSpeed = xSpeed;
this.ySpeed = ySpeed;
}
@Override
public void moveUp() {
y -= ySpeed;
}
@Override
public void moveDown() {
y += ySpeed;
}
@Override
public void moveLeft() {
x -= xSpeed;
}
@Override
public void moveRight() {
x += xSpeed;
}
@Override
public String toString() {
return String.format("MovablePoint (%1$d, %2$d) with xSpeed = %3$d and ySpeed = %4$d"
, x, y, xSpeed, ySpeed);
}
}