Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MovablePoint implements Movable {
- int x;
- int y;
- int xSpeed;
- int ySpeed;
- //Constructors
- public MovablePoint(int x, int y, int xSpeed, int ySpeed) {
- this.x = x;
- this.y = y;
- this.xSpeed = xSpeed;
- this.ySpeed = ySpeed;
- }
- //Movement Methods
- public void moveUp() {
- y -= ySpeed;
- }
- public void moveDown() {
- y += ySpeed;
- }
- public void moveLeft() {
- x -= xSpeed;
- }
- public void moveRight() {
- x += xSpeed;
- }
- //toString()
- public String toString() {
- return "(" + x + "," + y + ")";
- }
- }
- class MovableCircle implements Movable {
- private int radius;
- private MovablePoint center;
- public MovableCircle(int x, int y, int xSpeed, int ySpeed, int radius) {
- center = new MovablePoint(x, y, xSpeed, ySpeed);
- this.radius = radius;
- }
- public void moveUp() {
- center.moveUp();
- }
- public void moveDown() {
- center.moveDown();
- }
- public void moveLeft() {
- center.moveLeft();
- }
- public void moveRight() {
- center.moveRight();
- }
- public String toString() {
- return center.toString() + ", radius=" + radius;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement