public class CloneShapes1
{
  public static void main(String[] args)
  {
    Rect6 r = new Rect6(1, 2, 3, 4);
    System.out.println("Original rectangle:");
    System.out.println(r);

    Rect6 r2 = r.clone();        // trivial approach
    System.out.println("\nCloned rectangle:");
    System.out.println(r2);
  }
}

class Rect6 extends Shape 
{
  private int width;
  private int height;

  public Rect6(int xLoc, int yLoc, int width, int height)
  {
     super(xLoc, yLoc);
     this.width = width;
     this.height = height;
  }

  public double getArea()
  {
     return width * height;
  }

  public void stretchBy(double factor)
  {
     width =  (int)Math.round(width * factor);
     height = (int)Math.round(height * factor);
  }

  public String toString()
  {
     String str = "RECTANGLE \n"
                + super.toString()
                + "Width & Height: " + width + " " + height + "\n"
                + "Area: " + getArea();
     return str;
  }

  public Rect6 clone()
  {
    return new Rect6(getX(), getY(), width, height);
  }
}

