Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 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. class MovableRectangle implements Movable {
  41. private MovablePoint topLeft;
  42. private MovablePoint bottomRight;
  43.  
  44. MovableRectangle(int x1, int y1, int x2, int y2, int xSpeed, int ySpeed) {
  45. topLeft = new MovablePoint(x1, y1, xSpeed, ySpeed);
  46. bottomRight = new MovablePoint(x2, y2, xSpeed, ySpeed);
  47. }
  48.  
  49. public String toString() {
  50. return "(" + topLeft.x + "," + topLeft.y + "), (" + bottomRight.x + "," + bottomRight.y + ")";
  51. }
  52.  
  53. //Movement Methods
  54. public void moveUp() {
  55. topLeft.moveUp();
  56. bottomRight.moveUp();
  57. }
  58.  
  59. public void moveDown() {
  60. topLeft.moveDown();
  61. bottomRight.moveDown();
  62. }
  63.  
  64. public void moveLeft() {
  65. topLeft.moveLeft();
  66. bottomRight.moveLeft();
  67. }
  68.  
  69. public void moveRight() {
  70. topLeft.moveRight();
  71. bottomRight.moveRight();
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement