Code:
import java.awt.*;
public class Square extends Rectangle {
public Square(int x, int y, int length) {
this.setLocation(x,y);
this.setSize(length);
}
public Square() {
this(0,0,0);
}
public void setSize(int length) {
this.setSize(length, length);
}
public void setLength(int length) {
this.setSize(length);
}
public double getArea() {
return (this.getWidth() * this.getHeight());
}
public double getLength() {
return this.getWidth();
}
}
Code:
class SquareTest {
public static void main(String[] args) {
Square square = new Square(0,0,4);
System.out.println("Location: " + square.getLocation());
System.out.println("Length: " + square.getLength());
System.out.println("Area: " + square.getArea());
}
}
Now I need cash.