I have an assignment that calculates the area and perimeter of shapes.
The superclass:
public abstract class Shape implements Serializable {
private static final long serialVersionUID = -1231855623100981927L;
public abstract boolean draw();
public abstract String area();
public abstract String perimeter();
public abstract String characteristic();
}
Rectangle class:
public class Rectangle extends Shape {
private double x;
private double y;
public Rectangle() {}
public Rectangle(double x, double y) {
this.x = x;
this.y = y;
}
}
Square class:
public class Square extends Rectangle {
private double x;
public Square() {}
public Square(double side) {
super(side, side);
this.x = side;
}
public Square square(double side){
this.x = side;
return this;
}
}
Main class:
Shape rec = new Rectangle();
What I want is when the height and width of a rectangle are equal, it will return the Square
class instead of the Rectangle
class. That's all I want.