Classes representing figures on a plane The task is to write a class system that implements figures on the plane (point, segment, square, rectangle, triangle). Also, it is needed to provide encapsulation. There should be constructors and several methods that determine the size. Use the Has-a relationship.

Would you please review my code and say what is not correct here?

public class Pres12Task3 {

public static void main(String[] args) {
    Shape s = new Shape();
    Triangle t = new Triangle(1, 2, 3);
    System.out.println(t.width + "," + t.height + "," + t.getLength());
    t.changeSize(6);
}
}
class Shape {
int X;
int Y;

Shape() {
    X = 0;
    Y = 0;
}
public Shape(int x2, int y2) {
    // TODO Auto-generated constructor stub
}

void Move(int x, int y) {
    X = x;
    Y = y;
}}
class Point extends Shape {
Point(int x, int y) {
    // super();
    Move(x, y);
}}

class Segment extends Shape {
Segment(int x, int y) {
    super();
    Move(x, y);
}}
class Square extends Shape {
int width = 10;

Square(int w, int x, int y) {
    super(x, y);
    width = w;
}

void changeSize(int w) {
    width = w;
} }


class Rectangle extends Square {
int height = 9;

Rectangle(int w, int h, int x, int y) {
    super(w, x, y);
    height = h;
}

void changeSize(int w, int h) {
    super.changeSize(w);
    height = h;
}}

class Triangle extends Rectangle {
int length = 7;


Triangle(int l, int w, int h) {
    super(w, h, w, h);
    length = l;
}

public int getLength() {
    return length;
}

public void setLength(int length) {
    if (length &gt; 0) {
        this.length = length;
    } else {
        this.length = 5;
    }
}

void changeSize(int w, int l) {
    super.changeSize(w, l);
    length = l;
}}
Shape

A Shape is only an abstraction to unify different geometric constructs so my advice would be to make it an abstract class. (that is, a class that you cannot instantiate).

Point

Point as x and y coordinates. That's it. You have to decide if it inherits from Shape but from an OOP perspective I do agree with @simon-forsberg that it probably shouldn't.

Segment

Segment is defined by two Point and inherits from Shape. 

Triangle

Triangle is three Point and inherits from Shape.

And you can keep doing that for Rectangle and Square, just being careful with how you set up your constructors. Every classes should extend Shape but Point. 

Encapsulation

When you declare fields like x,y for Point, don't forget to give them a visibility modifier like private or protected (I assume you know what that means?) and then declare appropriate setter/getter.