Untitled

 avatar
unknown
plain_text
a year ago
1.5 kB
2
Indexable
interface moveable{
    void moveUp();
    void moveDown();
    void moveLeft();
    void moveRight();
}
class moveableCircle implements moveable{
    int up=-2, down=-2, left=-2, right=-2;
    public void moveUp(){
        System.out.println("Up is: " + (up+=2));
    }
    public void moveDown(){
        System.out.println("Down is: " +(down+=2));
    }
    public void moveLeft(){
        System.out.println("Left is: " +(left+=2));
    }
    public void moveRight(){
        System.out.println("Right is: " + (right+=2));
}
}


class MoveablePoint implements moveable{
    int up=0, down=0, left=0, right=0;
    public void moveUp(){
        System.out.println("Up is: " + ++up);
    }
    public void moveDown(){
        System.out.println("Down is: " + ++down);
    }
    public void moveLeft(){
        System.out.println("Left is: " + ++left);
    }
    public void moveRight(){
        System.out.println("Right is: " + ++right);
    }

}

public class Task2 {
    public static void main(String[] args) {

        MoveablePoint mov = new MoveablePoint();
        mov.moveUp();
        mov.moveUp();
        mov.moveDown();
        mov.moveDown();
        mov.moveLeft();
        mov.moveLeft();
        mov.moveRight();
        mov.moveRight();
        System.out.println("");
        moveableCircle mov2 = new moveableCircle();
        mov2.moveUp();
        mov2.moveUp();
        mov2.moveDown();
        mov2.moveDown();
        mov2.moveLeft();
        mov2.moveLeft();
        mov2.moveRight();
        mov2.moveRight();
    }
}
Leave a Comment