Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.work3_1;
- public class MovablePoint implements Movable{
- public int x;
- public int y;
- public int xSpeed;
- public int ySpeed;
- public MovablePoint(int x, int y, int xSpeed, int ySpeed){
- this.x = x;
- this.y = y;
- this.xSpeed = xSpeed;
- this.ySpeed = ySpeed;
- }
- @Override
- public String toString(){
- return " x: " + x + " y: " + y + " xSpeed " + xSpeed + " 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;
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////
- package com.work3_1;
- public class MovableCircle implements Movable{
- private final int radius;
- private final MovablePoint center;
- public MovableCircle(int x, int y, int xSpeed, int ySpeed, int radius){
- this.center = new MovablePoint(x, y, xSpeed, ySpeed);
- this.radius = radius;
- }
- @Override
- public String toString(){
- return "Центр x: " + center.x + " Центр y: " + center.y + " Радиус: " + radius;
- }
- @Override
- public void moveUp() {
- center.moveUp();
- }
- @Override
- public void moveDown() {
- center.moveDown();
- }
- @Override
- public void moveLeft() {
- center.moveLeft();
- }
- @Override
- public void moveRight() {
- center.moveRight();
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- package com.work3_1;
- public class MovableRectangle implements Movable{
- private final MovablePoint topLeft;
- private final MovablePoint bottomRight;
- public MovableRectangle(int x1, int y1, int x2, int y2, int xSpeed, int ySpeed){
- this.topLeft = new MovablePoint(x1, y1, xSpeed, ySpeed);
- this.bottomRight = new MovablePoint(x2, y2, xSpeed, ySpeed);
- }
- @Override
- public String toString() {
- return "Точка 1 : " + topLeft.x + " Точка 2: " + topLeft.y + " Точка 3: " + bottomRight.x + " Точка 4: " + bottomRight.y;
- }
- @Override
- public void moveUp() {
- topLeft.moveUp();
- bottomRight.moveUp();
- }
- @Override
- public void moveDown() {
- topLeft.moveDown();
- bottomRight.moveDown();
- }
- @Override
- public void moveLeft() {
- topLeft.moveLeft();
- bottomRight.moveLeft();
- }
- @Override
- public void moveRight() {
- topLeft.moveRight();
- bottomRight.moveRight();
- }
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- package com.work3_1;
- public class MainInterface {
- public static void main(String[] args){
- MovablePoint point = new MovablePoint(0, 0, 1, 1);
- System.out.println("Начальная координата: ");
- System.out.println(point);
- point.moveRight();
- point.moveUp();
- point.moveUp();
- System.out.println("Конечная координата: ");
- System.out.println(point);
- MovableCircle circle = new MovableCircle(0, 0, 1, 1, 2);
- System.out.println(circle);
- circle.moveUp();
- circle.moveRight();
- System.out.println(circle);
- MovableRectangle rectangle = new MovableRectangle(0, 0, 1, 1, 1, 1);
- System.out.println(rectangle);
- rectangle.moveDown();
- rectangle.moveLeft();
- System.out.println(rectangle);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement