0
    private Square wall;
public House()
{
    wall = new Square();
    wall.makeVisible();
    wall.changeSize(80);
    wall.moveHorizontal(40);
    wall.moveVertical(170);
}

private Triangle roof;
public House()
{
    roof = new Triangle();
    roof.makeVisible();
    roof.changeSize(50, 120);
    roof.moveHorizontal(90);
    roof.moveVertical(155);
    roof.changeColor("Black");
}

Edit: That fixed it but when I try adding this one I get the error again.

private Square window;
public House(Square window)
{
window = new Square();
}

I understand why I am getting this, because I already have 2 of the same constructors with the same signature. Is there anyway I could just merge them together?

  • Does this answer your question? [Best way to handle multiple constructors in Java](https://stackoverflow.com/questions/581873/best-way-to-handle-multiple-constructors-in-java) – Pouya Heydari Feb 28 '21 at 04:59

2 Answers2

0

yes! you could do someting like this:

public House()
{
    wall = new Square();
    wall.makeVisible();
    wall.changeSize(80);
    wall.moveHorizontal(40);
    wall.moveVertical(170);
    roof = new Triangle();
    roof.makeVisible();
    roof.changeSize(50, 120);
    roof.moveHorizontal(90);
    roof.moveVertical(155);
    roof.changeColor("Black");
}
0

Maybe considering constructor overloading . Overloading is a technique in which a class can have any number of constructors that differ in parameter list the reason why your code was not working it was because you have 2 constructors with same parameters.

private Square wall;
public House(Square wall)
{
    this.wall = new Square();
    this.wall.makeVisible();
    this.wall.changeSize(80);
    this.wall.moveHorizontal(40);
    this.wall.moveVertical(170);
}

private Triangle roof;
public House(Triangle roof)
{
    this.roof = new Triangle();
    this.roof.makeVisible();
    this.roof.changeSize(50, 120);
    this.roof.moveHorizontal(90);
    this.roof.moveVertical(155);
    this.roof.changeColor("Black");
}
Dren
  • 1,239
  • 1
  • 8
  • 17
  • No problem @JavaLearner dont forget to mark the answer as a correct one if it fixed your problem :) – Dren Feb 27 '21 at 21:57
  • another question if I was wanting to add another constructor with the class house while using square how would I go by doing that –  Feb 27 '21 at 21:59
  • check recent edit –  Feb 27 '21 at 22:02
  • Just add a constructor with all these atributes as a parameter public House(Triange roof,Square wall,Square window) { then here you initialize them – Dren Feb 27 '21 at 22:03