Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. class MovablePoint implements Movable {
  2. int x;
  3. int y;
  4. int xSpeed;
  5. int ySpeed;
  6.  
  7. //Constructors
  8. public MovablePoint(int x, int y, int xSpeed, int ySpeed) {
  9. this.x = x;
  10. this.y = y;
  11. this.xSpeed = xSpeed;
  12. this.ySpeed = ySpeed;
  13. }
  14.  
  15. //Movement Methods
  16. public void moveUp() {
  17. y -= ySpeed;
  18. }
  19.  
  20. public void moveDown() {
  21. y += ySpeed;
  22. }
  23.  
  24. public void moveLeft() {
  25. x -= xSpeed;
  26. }
  27.  
  28. public void moveRight() {
  29. x += xSpeed;
  30. }
  31.  
  32.  
  33. //toString()
  34. public String toString() {
  35. return "(" + x + "," + y + ")";
  36. }
  37. }
  38.  
  39.  
  40.  
  41. class MovableCircle implements Movable {
  42. private int radius;
  43. private MovablePoint center;
  44.  
  45. public MovableCircle(int x, int y, int xSpeed, int ySpeed, int radius) {
  46. center = new MovablePoint(x, y, xSpeed, ySpeed);
  47. this.radius = radius;
  48. }
  49.  
  50. public void moveUp() {
  51. center.moveUp();
  52. }
  53.  
  54. public void moveDown() {
  55. center.moveDown();
  56. }
  57.  
  58. public void moveLeft() {
  59. center.moveLeft();
  60. }
  61.  
  62. public void moveRight() {
  63. center.moveRight();
  64. }
  65.  
  66. public String toString() {
  67. return center.toString() + ", radius=" + radius;
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement