Advertisement
MKbear

JavaW3_1

Sep 7th, 2021
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.77 KB | None | 0 0
  1. package com.work3_1;
  2.  
  3. public class MovablePoint implements Movable{
  4.     public int x;
  5.     public int y;
  6.     public int xSpeed;
  7.     public int ySpeed;
  8.  
  9.     public MovablePoint(int x, int y, int xSpeed, int ySpeed){
  10.         this.x = x;
  11.         this.y = y;
  12.         this.xSpeed = xSpeed;
  13.         this.ySpeed = ySpeed;
  14.     }
  15.  
  16.     @Override
  17.     public String toString(){
  18.         return " x: " + x + " y: " + y + " xSpeed " + xSpeed + " ySpeed " + ySpeed;
  19.     }
  20.  
  21.     @Override
  22.     public void moveUp() {
  23.         y += ySpeed;
  24.     }
  25.  
  26.     @Override
  27.     public void moveDown() {
  28.         y -= ySpeed;
  29.     }
  30.  
  31.     @Override
  32.     public void moveLeft() {
  33.         x -= xSpeed;
  34.     }
  35.  
  36.     @Override
  37.     public void moveRight() {
  38.         x += xSpeed;
  39.     }
  40. }
  41. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  42.  
  43. package com.work3_1;
  44.  
  45. public class MovableCircle implements Movable{
  46.     private final int radius;
  47.     private final MovablePoint center;
  48.  
  49.     public MovableCircle(int x, int y, int xSpeed, int ySpeed, int radius){
  50.         this.center = new MovablePoint(x, y, xSpeed, ySpeed);
  51.         this.radius = radius;
  52.     }
  53.  
  54.     @Override
  55.     public String toString(){
  56.         return "Центр x: " + center.x + " Центр y: " + center.y + " Радиус: " + radius;
  57.     }
  58.  
  59.     @Override
  60.     public void moveUp() {
  61.         center.moveUp();
  62.     }
  63.  
  64.     @Override
  65.     public void moveDown() {
  66.         center.moveDown();
  67.     }
  68.  
  69.     @Override
  70.     public void moveLeft() {
  71.         center.moveLeft();
  72.     }
  73.  
  74.     @Override
  75.     public void moveRight() {
  76.         center.moveRight();
  77.     }
  78. }
  79. ///////////////////////////////////////////////////////////////////////////////////////////////////
  80. package com.work3_1;
  81.  
  82. public class MovableRectangle implements Movable{
  83.     private final MovablePoint topLeft;
  84.     private final MovablePoint bottomRight;
  85.  
  86.     public MovableRectangle(int x1, int y1, int x2, int y2, int xSpeed, int ySpeed){
  87.         this.topLeft = new MovablePoint(x1, y1, xSpeed, ySpeed);
  88.         this.bottomRight = new MovablePoint(x2, y2, xSpeed, ySpeed);
  89.     }
  90.  
  91.     @Override
  92.     public String toString() {
  93.         return "Точка 1 : " + topLeft.x + " Точка 2: " + topLeft.y + " Точка 3: " + bottomRight.x + " Точка 4: " + bottomRight.y;
  94.     }
  95.  
  96.     @Override
  97.     public void moveUp() {
  98.         topLeft.moveUp();
  99.         bottomRight.moveUp();
  100.     }
  101.  
  102.     @Override
  103.     public void moveDown() {
  104.         topLeft.moveDown();
  105.         bottomRight.moveDown();
  106.     }
  107.  
  108.     @Override
  109.     public void moveLeft() {
  110.         topLeft.moveLeft();
  111.         bottomRight.moveLeft();
  112.     }
  113.  
  114.     @Override
  115.     public void moveRight() {
  116.         topLeft.moveRight();
  117.         bottomRight.moveRight();
  118.     }
  119. }
  120. ////////////////////////////////////////////////////////////////////////////////////////////////////////
  121. package com.work3_1;
  122.  
  123. public class MainInterface {
  124.     public static void main(String[] args){
  125.         MovablePoint point = new MovablePoint(0, 0, 1, 1);
  126.         System.out.println("Начальная координата: ");
  127.         System.out.println(point);
  128.         point.moveRight();
  129.         point.moveUp();
  130.         point.moveUp();
  131.         System.out.println("Конечная координата: ");
  132.         System.out.println(point);
  133.         MovableCircle circle = new MovableCircle(0, 0, 1, 1, 2);
  134.         System.out.println(circle);
  135.         circle.moveUp();
  136.         circle.moveRight();
  137.         System.out.println(circle);
  138.         MovableRectangle rectangle = new MovableRectangle(0, 0, 1, 1, 1, 1);
  139.         System.out.println(rectangle);
  140.         rectangle.moveDown();
  141.         rectangle.moveLeft();
  142.         System.out.println(rectangle);
  143.     }
  144. }
  145.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement